/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dieci.ui;

import dieci.exceptions.StockNotAvailableException;
import dieci.managers.clientmanager.ClientManager;
import dieci.managers.ordermanager.OrderManager;
import dieci.managers.rawmaterial.OrderRawMaterialManager;
import dieci.managers.rawmaterial.RawMaterialManager;
import dieci.managers.rawmaterial.RawMaterialStockManager;
import dieci.managers.returnmanager.ReturnManager;
import dieci.managers.stockmanager.ProductManager;
import dieci.managers.stockmanager.StockManager;
import dieci.managers.supplier.SupplierManager;
import dieci.system.Client;
import dieci.system.Order;
import dieci.system.OrderDetails;
import dieci.system.OrderRawMaterial;
import dieci.system.OrderRawMaterialDetails;
import dieci.system.Product;
import dieci.system.Price;
import dieci.system.ProductStock;
import dieci.system.RawMaterial;
import dieci.system.RawMaterialStock;
import dieci.system.Return;
import dieci.system.ReturnDetails;
import dieci.system.Sale;
import dieci.system.SaleDetails;
import dieci.system.Supplier;
import dieci.ui.handlers.UISaleHandler;
import dieci.utils.Constants;
import dieci.utils.Redondeo;
import static java.awt.Frame.MAXIMIZED_BOTH;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.ListModel;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author Pc
 */
public class DieciUI extends javax.swing.JFrame
{

    private final ProductManager productManager;
    private final ClientManager clientManager;
    private final SupplierManager supplierManager;
    private final RawMaterialManager rawMaterialManager;
    private final OrderManager orderManager;
    private final StockManager stockManager;
    private final UISaleHandler uISaleHandler;
    private final ReturnManager returnManager;
    private final OrderRawMaterialManager orderRawMaterialManager;
    private final RawMaterialStockManager rawMaterialStockManager;
    
    /**
     * Creates new form DieciUI
     */
    public DieciUI()
    {
        productManager = new ProductManager();
        clientManager = new ClientManager();
        supplierManager = new SupplierManager();
        rawMaterialManager = new RawMaterialManager();
        orderManager = new OrderManager();
        stockManager = new StockManager();
        uISaleHandler = new UISaleHandler();
        returnManager = new ReturnManager();
        orderRawMaterialManager = new OrderRawMaterialManager();
        rawMaterialStockManager = new RawMaterialStockManager();
                
        initComponents();
        
        //FILL TABLES FROM DB DATA
        getAllProductsFromDB();
        getAllClientsFromDB();
        getAllSuppliersFromDB();
        getAllMatPrimaFromDB();
        getAllOrdersFromDB();
        getAllSalesFromDB();
        getAllReturnsFromDB();
        getAllOrdersRawMaterialFromDB();
        
        //get suppliers to fill combo box
        fillSupplierComboBox();
        fillSupplierComboBoxRawMaterial();
        //get clients to fill combo box
        fillClientsComboBox();
        
        addTabListenerForProductPanel();
                       
        ImageIcon imageIcon = new javax.swing.ImageIcon(getClass().getResource("/dieci/ui/icon_image.jpg"));
        this.setIconImage(imageIcon.getImage());
        this.setExtendedState(MAXIMIZED_BOTH);
        this.setVisible(true);        
        setAllPanelsInvisible();
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroupDiscount = new javax.swing.ButtonGroup();
        buttonGroupOrdersSearch = new javax.swing.ButtonGroup();
        North = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButtonRefreshTable = new javax.swing.JButton();
        jButtonUpdateProductsPrice = new javax.swing.JButton();
        East = new javax.swing.JPanel();
        Center = new javax.swing.JPanel();
        jProductsPanel = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldArticulo = new javax.swing.JTextField();
        jButtonEditProduct = new javax.swing.JButton();
        jTextFieldNombre = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextAreaDesc = new javax.swing.JTextArea();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldPrecio = new javax.swing.JTextField();
        jTextFieldColor = new javax.swing.JTextField();
        jComboBoxTalle = new javax.swing.JComboBox();
        jButtonGuardarProducto = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jButtonCancelarProducto = new javax.swing.JButton();
        jButtonEliminarProducto = new javax.swing.JButton();
        jLabel48 = new javax.swing.JLabel();
        jLabel49 = new javax.swing.JLabel();
        jLabel50 = new javax.swing.JLabel();
        jLabelStockAvailable = new javax.swing.JLabel();
        jLabelStockOnReturn = new javax.swing.JLabel();
        jLabelStockTotal = new javax.swing.JLabel();
        jClientesPanel = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldNomCliente = new javax.swing.JTextField();
        jButtonEditarCliente = new javax.swing.JButton();
        jTextFieldTelCliente = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jButtonGuardarCliente = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jButtonCancelarCliente = new javax.swing.JButton();
        jTextFieldEmailCliente = new javax.swing.JTextField();
        jButtonEliminarCliente = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        jTextFieldClienteContacto = new javax.swing.JTextField();
        jTextFieldClienteDir = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jTextFieldClienteWeb = new javax.swing.JTextField();
        jSuppliersPanel = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jTextFieldNomSupplier = new javax.swing.JTextField();
        jButtonEditarProveedor = new javax.swing.JButton();
        jButtonGuardarProveedor = new javax.swing.JButton();
        jLabel16 = new javax.swing.JLabel();
        jButtonCancelarProveedor = new javax.swing.JButton();
        jButtonEliminarProveedor = new javax.swing.JButton();
        jLabel24 = new javax.swing.JLabel();
        jTextFieldProvContacto = new javax.swing.JTextField();
        jLabel25 = new javax.swing.JLabel();
        jTextFieldProvDir = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        jTextFieldProvTel = new javax.swing.JTextField();
        jLabel27 = new javax.swing.JLabel();
        jTextFieldProvEmail = new javax.swing.JTextField();
        jLabel28 = new javax.swing.JLabel();
        jTextFieldProvWeb = new javax.swing.JTextField();
        jMatPrimaPanel = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jTextFieldMatPrimaNom = new javax.swing.JTextField();
        jButtonEditarMatPrima = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jTextFieldMatPrimaPrecio = new javax.swing.JTextField();
        jTextFieldMatPrimaCant = new javax.swing.JTextField();
        jButtonGuardarMatPrima = new javax.swing.JButton();
        jLabel21 = new javax.swing.JLabel();
        jButtonCancelarMatPrima = new javax.swing.JButton();
        jButtonEliminarMatPrima = new javax.swing.JButton();
        jComboBoxUniMedida = new javax.swing.JComboBox();
        jOrdersPanel = new javax.swing.JPanel();
        jLabel22 = new javax.swing.JLabel();
        jButtonEditOrder = new javax.swing.JButton();
        jButtonGuardarOrder = new javax.swing.JButton();
        jLabel34 = new javax.swing.JLabel();
        jButtonCancelarOrder = new javax.swing.JButton();
        jButtonEliminarOrder = new javax.swing.JButton();
        jComboBoxProveedor = new javax.swing.JComboBox();
        jLabel35 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldBuscarProd = new javax.swing.JTextField();
        jButtonBuscarProductos = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListProductos = new javax.swing.JList();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTableProductosPedido = new javax.swing.JTable();
        jLabel29 = new javax.swing.JLabel();
        jLabel38 = new javax.swing.JLabel();
        MaskFormatter mfOrder = null;
        try {
            mfOrder = new MaskFormatter("##/##/####");
        } catch (ParseException p) {
            p.printStackTrace();
        }
        jTextFieldOrderDate = new javax.swing.JFormattedTextField(mfOrder);
        jLabel31 = new javax.swing.JLabel();
        jTextFieldTotalOrder = new javax.swing.JTextField();
        jReturnsPanel = new javax.swing.JPanel();
        jButtonEditReturn = new javax.swing.JButton();
        jButtonGuardarReturn = new javax.swing.JButton();
        jLabel36 = new javax.swing.JLabel();
        jButtonCancelarReturn = new javax.swing.JButton();
        jButtonEliminarReturn = new javax.swing.JButton();
        jLabel37 = new javax.swing.JLabel();
        jButtonBuscarPedidos = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        jListPedidos = new javax.swing.JList();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTableProductosPedidosDevol = new javax.swing.JTable();
        jLabel32 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        MaskFormatter mfRet = null;
        try {
            mfRet = new MaskFormatter("##/##/####");
        } catch (ParseException p) {
            p.printStackTrace();
        }
        jTextFieldReturnDate = new javax.swing.JFormattedTextField(mfRet);
        jRadioButtonDateSearch = new javax.swing.JRadioButton();
        jRadioButtonSupplierSearch = new javax.swing.JRadioButton();
        jLabelDateSince = new javax.swing.JLabel();
        MaskFormatter mf2 = null;
        int dia_2=0,mes_2=0,anio_2=0;
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            anio_2 = calendar.get(Calendar.YEAR);
            mes_2 = calendar.get(Calendar.MONTH)+1;
            dia_2 = calendar.get(Calendar.DAY_OF_MONTH);

            mf2 = new MaskFormatter("##/##/####");

        } catch (ParseException p) {
            p.printStackTrace();
        }
        jTextFieldDateSince = new javax.swing.JFormattedTextField(mf2);
        jLabelDateTo = new javax.swing.JLabel();
        MaskFormatter mf3 = null;
        int dia_3=0,mes_3=0,anio_3=0;
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            anio_3 = calendar.get(Calendar.YEAR);
            mes_3 = calendar.get(Calendar.MONTH)+1;
            dia_3 = calendar.get(Calendar.DAY_OF_MONTH);

            mf3 = new MaskFormatter("##/##/####");

        } catch (ParseException p) {
            p.printStackTrace();
        }
        jTextFieldDateTo = new javax.swing.JFormattedTextField(mf3);
        jLabelSupplier = new javax.swing.JLabel();
        jTextFieldSupplier = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        jSalesPanel = new javax.swing.JPanel();
        jLabel39 = new javax.swing.JLabel();
        jButtonEditSale = new javax.swing.JButton();
        jButtonGuardarSale = new javax.swing.JButton();
        jLabel40 = new javax.swing.JLabel();
        jButtonCancelarSale = new javax.swing.JButton();
        jButtonEliminarSale = new javax.swing.JButton();
        jComboBoxClient = new javax.swing.JComboBox();
        jLabel41 = new javax.swing.JLabel();
        jLabel42 = new javax.swing.JLabel();
        jTextFieldBuscarProdSale = new javax.swing.JTextField();
        jButtonBuscarProductosSale = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        jListProductosSale = new javax.swing.JList();
        jScrollPane7 = new javax.swing.JScrollPane();
        jTableProductosSale = new javax.swing.JTable();
        jLabel43 = new javax.swing.JLabel();
        jLabel44 = new javax.swing.JLabel();
        MaskFormatter mfSale = null;
        try {
            mfSale = new MaskFormatter("##/##/####");
        } catch (ParseException p) {
            p.printStackTrace();
        }
        jTextFieldSaleDate = new javax.swing.JFormattedTextField(mfSale);
        jLabel45 = new javax.swing.JLabel();
        jTextFieldSaleSubTotal = new javax.swing.JTextField();
        jRadioButtonPercentDisc = new javax.swing.JRadioButton();
        jRadioButtonFixedDisc = new javax.swing.JRadioButton();
        jLabel46 = new javax.swing.JLabel();
        jTextFieldDiscountSale = new javax.swing.JTextField();
        jLabel47 = new javax.swing.JLabel();
        jTextFieldTotalSale = new javax.swing.JTextField();
        jButtonCalTotalSale = new javax.swing.JButton();
        jCheckBoxChargedSale = new javax.swing.JCheckBox();
        jCheckBoxDeliveredSale = new javax.swing.JCheckBox();
        jOrdersRawMaterialPanel = new javax.swing.JPanel();
        jLabel51 = new javax.swing.JLabel();
        jButtonEditOrderRawMaterial = new javax.swing.JButton();
        jButtonGuardarOrderRawMaterial = new javax.swing.JButton();
        jLabel52 = new javax.swing.JLabel();
        jButtonCancelarOrderRawMaterial = new javax.swing.JButton();
        jButtonEliminarOrderRawMaterial = new javax.swing.JButton();
        jComboBoxProveedorRawMaterial = new javax.swing.JComboBox();
        jLabel53 = new javax.swing.JLabel();
        jLabel54 = new javax.swing.JLabel();
        jTextFieldBuscarRawMaterial = new javax.swing.JTextField();
        jButtonBuscarRawMaterial = new javax.swing.JButton();
        jScrollPane8 = new javax.swing.JScrollPane();
        jListRawMaterial = new javax.swing.JList();
        jScrollPane9 = new javax.swing.JScrollPane();
        jTableRawMaterialPedido = new javax.swing.JTable();
        jLabel55 = new javax.swing.JLabel();
        jLabel56 = new javax.swing.JLabel();
        MaskFormatter mfOrderRawMat = null;
        try {
            mfOrderRawMat = new MaskFormatter("##/##/####");
        } catch (ParseException p) {
            p.printStackTrace();
        }
        jTextFieldOrderRawMaterialDate = new javax.swing.JFormattedTextField(mfOrderRawMat);
        jLabel57 = new javax.swing.JLabel();
        jTextFieldTotalOrderRawMaterial = new javax.swing.JTextField();
        jOrderRawMaterialIDTextField = new javax.swing.JTextField();
        jPricePanel = new javax.swing.JPanel();
        jButtonGuardarPrecios = new javax.swing.JButton();
        jLabel59 = new javax.swing.JLabel();
        jButtonCancelarPrecios = new javax.swing.JButton();
        jLabel61 = new javax.swing.JLabel();
        jTextFieldBuscarProdActualizar = new javax.swing.JTextField();
        jButtonBuscarProductosActPrecio = new javax.swing.JButton();
        jScrollPane10 = new javax.swing.JScrollPane();
        jListProductosActualizar = new javax.swing.JList();
        jScrollPane11 = new javax.swing.JScrollPane();
        jTableProductosNuevoPrecio = new javax.swing.JTable();
        jLabel62 = new javax.swing.JLabel();
        jLabel65 = new javax.swing.JLabel();
        jPorcentajePrecioTextField = new javax.swing.JTextField();
        jIncreasePriceButton = new javax.swing.JButton();
        jDecreasePriceButton = new javax.swing.JButton();
        jFixedNewPriceTextField = new javax.swing.JTextField();
        jLabel58 = new javax.swing.JLabel();
        jOkNewPriceButton = new javax.swing.JButton();
        jLabel63 = new javax.swing.JLabel();
        jImagenFondo = new javax.swing.JLabel();
        South = new javax.swing.JPanel();
        West = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanelProducts = new javax.swing.JPanel();
        jScrollPaneProducts = new javax.swing.JScrollPane();
        jTableProducts = new javax.swing.JTable();
        jPanelClients = new javax.swing.JPanel();
        jScrollPaneClients = new javax.swing.JScrollPane();
        jTableClients = new javax.swing.JTable();
        jPanelSupplier = new javax.swing.JPanel();
        jScrollPaneSuppliers = new javax.swing.JScrollPane();
        jTableSuppliers = new javax.swing.JTable();
        jPanelMateriaPrima = new javax.swing.JPanel();
        jScrollPaneMatPrima = new javax.swing.JScrollPane();
        jTableMatPrima = new javax.swing.JTable();
        jPanelOrders = new javax.swing.JPanel();
        jScrollPaneOrders = new javax.swing.JScrollPane();
        jTableOrders = new javax.swing.JTable();
        jPanelReturns = new javax.swing.JPanel();
        jScrollPaneReturns = new javax.swing.JScrollPane();
        jTableReturns = new javax.swing.JTable();
        jPanelSales = new javax.swing.JPanel();
        jScrollPaneSales = new javax.swing.JScrollPane();
        jTableSales = new javax.swing.JTable();
        jPanelOrdersRawMaterial = new javax.swing.JPanel();
        jScrollPaneOrdersRawMaterial = new javax.swing.JScrollPane();
        jTableOrdersRawMaterial = new javax.swing.JTable();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        openMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        contentsMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Dieci");
        setName("mainWindow"); // NOI18N
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
                formWindowLostFocus(evt);
            }
        });

        North.setBackground(new java.awt.Color(241, 245, 255));
        North.setPreferredSize(new java.awt.Dimension(1075, 40));

        jButton1.setBackground(new java.awt.Color(0, 153, 204));
        jButton1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButton1.setForeground(new java.awt.Color(255, 255, 255));
        jButton1.setText("Nuevo");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButtonRefreshTable.setBackground(new java.awt.Color(0, 153, 204));
        jButtonRefreshTable.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonRefreshTable.setForeground(new java.awt.Color(255, 255, 255));
        jButtonRefreshTable.setText("Refrescar tabla");
        jButtonRefreshTable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRefreshTableActionPerformed(evt);
            }
        });

        jButtonUpdateProductsPrice.setBackground(new java.awt.Color(0, 153, 204));
        jButtonUpdateProductsPrice.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonUpdateProductsPrice.setForeground(new java.awt.Color(255, 255, 255));
        jButtonUpdateProductsPrice.setText("Actualizar Precios Venta");
        jButtonUpdateProductsPrice.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonUpdateProductsPriceActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout NorthLayout = new javax.swing.GroupLayout(North);
        North.setLayout(NorthLayout);
        NorthLayout.setHorizontalGroup(
            NorthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(NorthLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonRefreshTable)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonUpdateProductsPrice)
                .addContainerGap(654, Short.MAX_VALUE))
        );
        NorthLayout.setVerticalGroup(
            NorthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, NorthLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(NorthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButtonRefreshTable)
                    .addComponent(jButtonUpdateProductsPrice))
                .addContainerGap())
        );

        getContentPane().add(North, java.awt.BorderLayout.NORTH);

        East.setBackground(new java.awt.Color(241, 245, 255));
        East.setPreferredSize(new java.awt.Dimension(30, 541));

        javax.swing.GroupLayout EastLayout = new javax.swing.GroupLayout(East);
        East.setLayout(EastLayout);
        EastLayout.setHorizontalGroup(
            EastLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 30, Short.MAX_VALUE)
        );
        EastLayout.setVerticalGroup(
            EastLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 588, Short.MAX_VALUE)
        );

        getContentPane().add(East, java.awt.BorderLayout.EAST);
        East.getAccessibleContext().setAccessibleName("");

        Center.setBackground(new java.awt.Color(241, 245, 255));
        Center.setLayout(null);

        jProductsPanel.setBackground(new java.awt.Color(255, 255, 255));
        jProductsPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(0, 0, 0)));

        jLabel3.setText("Articulo:");

        jTextFieldArticulo.setEditable(false);
        jTextFieldArticulo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldArticuloActionPerformed(evt);
            }
        });
        jTextFieldArticulo.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                jTextFieldArticuloInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        jTextFieldArticulo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldArticuloKeyTyped(evt);
            }
        });

        jButtonEditProduct.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEditProduct.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEditProduct.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEditProduct.setText("Editar");
        jButtonEditProduct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditProductActionPerformed(evt);
            }
        });

        jTextFieldNombre.setEditable(false);

        jLabel4.setText("Nombre:");

        jLabel5.setText("Descripcion:");

        jTextAreaDesc.setEditable(false);
        jTextAreaDesc.setColumns(20);
        jTextAreaDesc.setRows(5);
        jTextAreaDesc.setTabSize(0);
        jTextAreaDesc.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextAreaDescKeyPressed(evt);
            }
        });
        jScrollPane2.setViewportView(jTextAreaDesc);

        jLabel6.setText("Talle:");

        jLabel7.setText("Color:");

        jLabel8.setText("Precio $:");

        jTextFieldPrecio.setEditable(false);

        jTextFieldColor.setEditable(false);

        jComboBoxTalle.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "N/A", "0M", "3M", "6M" }));
        jComboBoxTalle.setEnabled(false);

        jButtonGuardarProducto.setBackground(new java.awt.Color(0, 153, 204));
        jButtonGuardarProducto.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonGuardarProducto.setForeground(new java.awt.Color(255, 255, 255));
        jButtonGuardarProducto.setText("Guardar");
        jButtonGuardarProducto.setEnabled(false);
        jButtonGuardarProducto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarProductoActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("PRODUCTO");

        jButtonCancelarProducto.setBackground(new java.awt.Color(0, 153, 204));
        jButtonCancelarProducto.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonCancelarProducto.setForeground(new java.awt.Color(255, 255, 255));
        jButtonCancelarProducto.setText("Cancelar");
        jButtonCancelarProducto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarProductoActionPerformed(evt);
            }
        });

        jButtonEliminarProducto.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEliminarProducto.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEliminarProducto.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEliminarProducto.setText("Eliminar");
        jButtonEliminarProducto.setEnabled(false);
        jButtonEliminarProducto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEliminarProductoActionPerformed(evt);
            }
        });

        jLabel48.setText("Cantidad Stock Disponible:");

        jLabel49.setText("Cantidad Stock en Devolucion:");

        jLabel50.setText("Cantidad Stock Total:");

        jLabelStockAvailable.setText("jLabel51");

        jLabelStockOnReturn.setText("jLabel52");

        jLabelStockTotal.setText("jLabel53");

        javax.swing.GroupLayout jProductsPanelLayout = new javax.swing.GroupLayout(jProductsPanel);
        jProductsPanel.setLayout(jProductsPanelLayout);
        jProductsPanelLayout.setHorizontalGroup(
            jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jProductsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jProductsPanelLayout.createSequentialGroup()
                        .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jProductsPanelLayout.createSequentialGroup()
                                .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jComboBoxTalle, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldColor, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(jProductsPanelLayout.createSequentialGroup()
                                .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextFieldArticulo, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldNombre)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(43, 43, 43)
                                .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jProductsPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel50)
                                        .addGap(0, 0, Short.MAX_VALUE))
                                    .addComponent(jLabel49, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)
                                    .addComponent(jLabel48, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelStockAvailable)
                                    .addComponent(jLabelStockOnReturn)
                                    .addComponent(jLabelStockTotal))))
                        .addGap(199, 199, 199))
                    .addGroup(jProductsPanelLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonEditProduct)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonGuardarProducto)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonEliminarProducto)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonCancelarProducto)
                        .addGap(77, 77, 77))))
        );
        jProductsPanelLayout.setVerticalGroup(
            jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jProductsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButtonEditProduct)
                        .addComponent(jButtonGuardarProducto)
                        .addComponent(jButtonCancelarProducto)
                        .addComponent(jButtonEliminarProducto))
                    .addComponent(jLabel2))
                .addGap(53, 53, 53)
                .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldArticulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jProductsPanelLayout.createSequentialGroup()
                        .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jProductsPanelLayout.createSequentialGroup()
                        .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel48)
                            .addComponent(jLabelStockAvailable))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel49)
                            .addComponent(jLabelStockOnReturn))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel50)
                            .addComponent(jLabelStockTotal))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxTalle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldColor, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jProductsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(73, Short.MAX_VALUE))
        );

        Center.add(jProductsPanel);
        jProductsPanel.setBounds(20, 20, 780, 400);

        jClientesPanel.setBackground(new java.awt.Color(255, 255, 255));
        jClientesPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(0, 0, 0)));
        jClientesPanel.setMinimumSize(new java.awt.Dimension(680, 288));

        jLabel9.setText("Nombre:");

        jTextFieldNomCliente.setEditable(false);
        jTextFieldNomCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldNomClienteActionPerformed(evt);
            }
        });
        jTextFieldNomCliente.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                jTextFieldNomClienteInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        jTextFieldNomCliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldNomClienteKeyTyped(evt);
            }
        });

        jButtonEditarCliente.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEditarCliente.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEditarCliente.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEditarCliente.setText("Editar");
        jButtonEditarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditarClienteActionPerformed(evt);
            }
        });

        jTextFieldTelCliente.setEditable(false);

        jLabel10.setText("Telefono:");

        jLabel11.setText("email:");

        jButtonGuardarCliente.setBackground(new java.awt.Color(0, 153, 204));
        jButtonGuardarCliente.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonGuardarCliente.setForeground(new java.awt.Color(255, 255, 255));
        jButtonGuardarCliente.setText("Guardar");
        jButtonGuardarCliente.setEnabled(false);
        jButtonGuardarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarClienteActionPerformed(evt);
            }
        });

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel15.setText("CLIENTE");

        jButtonCancelarCliente.setBackground(new java.awt.Color(0, 153, 204));
        jButtonCancelarCliente.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonCancelarCliente.setForeground(new java.awt.Color(255, 255, 255));
        jButtonCancelarCliente.setText("Cancelar");
        jButtonCancelarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarClienteActionPerformed(evt);
            }
        });

        jTextFieldEmailCliente.setEditable(false);

        jButtonEliminarCliente.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEliminarCliente.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEliminarCliente.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEliminarCliente.setText("Eliminar");
        jButtonEliminarCliente.setEnabled(false);
        jButtonEliminarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEliminarClienteActionPerformed(evt);
            }
        });

        jLabel17.setText("Contacto:");

        jTextFieldClienteContacto.setEditable(false);
        jTextFieldClienteContacto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldClienteContactoActionPerformed(evt);
            }
        });
        jTextFieldClienteContacto.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                jTextFieldClienteContactoInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        jTextFieldClienteContacto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldClienteContactoKeyTyped(evt);
            }
        });

        jTextFieldClienteDir.setEditable(false);
        jTextFieldClienteDir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldClienteDirActionPerformed(evt);
            }
        });
        jTextFieldClienteDir.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                jTextFieldClienteDirInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        jTextFieldClienteDir.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldClienteDirKeyTyped(evt);
            }
        });

        jLabel18.setText("Direccion:");

        jLabel23.setText("Sitio WEB:");

        jTextFieldClienteWeb.setEditable(false);
        jTextFieldClienteWeb.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldClienteWebActionPerformed(evt);
            }
        });
        jTextFieldClienteWeb.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                jTextFieldClienteWebInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        jTextFieldClienteWeb.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldClienteWebKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jClientesPanelLayout = new javax.swing.GroupLayout(jClientesPanel);
        jClientesPanel.setLayout(jClientesPanelLayout);
        jClientesPanelLayout.setHorizontalGroup(
            jClientesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jClientesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jClientesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jClientesPanelLayout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
                        .addComponent(jButtonEditarCliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonGuardarCliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonEliminarCliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonCancelarCliente)
                        .addGap(29, 29, 29))
                    .addGroup(jClientesPanelLayout.createSequentialGroup()
                        .addGroup(jClientesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jClientesPanelLayout.createSequentialGroup()
                                .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldClienteContacto))
                            .addGroup(jClientesPanelLayout.createSequentialGroup()
                                .addGroup(jClientesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jClientesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldEmailCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE)
                                    .addGroup(jClientesPanelLayout.createSequentialGroup()
                                        .addComponent(jTextFieldTelCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(0, 0, Short.MAX_VALUE))
                                    .addComponent(jTextFieldNomCliente))))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jClientesPanelLayout.createSequentialGroup()
                        .addGroup(jClientesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jClientesPanelLayout.createSequentialGroup()
                                .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldClienteDir, javax.swing.GroupLayout.PREFERRED_SIZE, 309, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jClientesPanelLayout.createSequentialGroup()
                                .addComponent(jLabel23, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldClienteWeb, javax.swing.GroupLayout.PREFERRED_SIZE, 397, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        jClientesPanelLayout.setVerticalGroup(
            jClientesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jClientesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jClientesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(jButtonEditarCliente)
                    .addComponent(jButtonGuardarCliente)
                    .addComponent(jButtonCancelarCliente)
                    .addComponent(jButtonEliminarCliente))
                .addGap(52, 52, 52)
                .addGroup(jClientesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNomCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jClientesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldClienteContacto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(4, 4, 4)
                .addGroup(jClientesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldClienteDir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jClientesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldTelCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jClientesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldEmailCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jClientesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldClienteWeb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(50, Short.MAX_VALUE))
        );

        Center.add(jClientesPanel);
        jClientesPanel.setBounds(20, 20, 680, 288);

        jSuppliersPanel.setBackground(new java.awt.Color(255, 255, 255));
        jSuppliersPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(0, 0, 0)));
        jSuppliersPanel.setMaximumSize(new java.awt.Dimension(680, 210));
        jSuppliersPanel.setMinimumSize(new java.awt.Dimension(680, 210));

        jLabel12.setText("Nombre:");

        jTextFieldNomSupplier.setEditable(false);
        jTextFieldNomSupplier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldNomSupplierActionPerformed(evt);
            }
        });
        jTextFieldNomSupplier.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                jTextFieldNomSupplierInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        jTextFieldNomSupplier.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldNomSupplierKeyTyped(evt);
            }
        });

        jButtonEditarProveedor.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEditarProveedor.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEditarProveedor.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEditarProveedor.setText("Editar");
        jButtonEditarProveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditarProveedorActionPerformed(evt);
            }
        });

        jButtonGuardarProveedor.setBackground(new java.awt.Color(0, 153, 204));
        jButtonGuardarProveedor.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonGuardarProveedor.setForeground(new java.awt.Color(255, 255, 255));
        jButtonGuardarProveedor.setText("Guardar");
        jButtonGuardarProveedor.setEnabled(false);
        jButtonGuardarProveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarProveedorActionPerformed(evt);
            }
        });

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel16.setText("PROVEEDOR");

        jButtonCancelarProveedor.setBackground(new java.awt.Color(0, 153, 204));
        jButtonCancelarProveedor.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonCancelarProveedor.setForeground(new java.awt.Color(255, 255, 255));
        jButtonCancelarProveedor.setText("Cancelar");
        jButtonCancelarProveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarProveedorActionPerformed(evt);
            }
        });

        jButtonEliminarProveedor.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEliminarProveedor.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEliminarProveedor.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEliminarProveedor.setText("Eliminar");
        jButtonEliminarProveedor.setEnabled(false);
        jButtonEliminarProveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEliminarProveedorActionPerformed(evt);
            }
        });

        jLabel24.setText("Contacto:");

        jTextFieldProvContacto.setEditable(false);
        jTextFieldProvContacto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldProvContactoActionPerformed(evt);
            }
        });
        jTextFieldProvContacto.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                jTextFieldProvContactoInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        jTextFieldProvContacto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldProvContactoKeyTyped(evt);
            }
        });

        jLabel25.setText("Direccion:");

        jTextFieldProvDir.setEditable(false);
        jTextFieldProvDir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldProvDirActionPerformed(evt);
            }
        });
        jTextFieldProvDir.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                jTextFieldProvDirInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        jTextFieldProvDir.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldProvDirKeyTyped(evt);
            }
        });

        jLabel26.setText("Telefono:");

        jTextFieldProvTel.setEditable(false);

        jLabel27.setText("email:");

        jTextFieldProvEmail.setEditable(false);

        jLabel28.setText("Sitio WEB:");

        jTextFieldProvWeb.setEditable(false);
        jTextFieldProvWeb.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldProvWebActionPerformed(evt);
            }
        });
        jTextFieldProvWeb.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                jTextFieldProvWebInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        jTextFieldProvWeb.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldProvWebKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jSuppliersPanelLayout = new javax.swing.GroupLayout(jSuppliersPanel);
        jSuppliersPanel.setLayout(jSuppliersPanelLayout);
        jSuppliersPanelLayout.setHorizontalGroup(
            jSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jSuppliersPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jSuppliersPanelLayout.createSequentialGroup()
                        .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldNomSupplier, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jSuppliersPanelLayout.createSequentialGroup()
                        .addComponent(jLabel16)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 224, Short.MAX_VALUE)
                        .addComponent(jButtonEditarProveedor)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonGuardarProveedor)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonEliminarProveedor)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonCancelarProveedor)
                        .addGap(29, 29, 29))
                    .addGroup(jSuppliersPanelLayout.createSequentialGroup()
                        .addGroup(jSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jSuppliersPanelLayout.createSequentialGroup()
                                    .addComponent(jLabel24, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextFieldProvContacto))
                                .addGroup(jSuppliersPanelLayout.createSequentialGroup()
                                    .addGroup(jSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jLabel27, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel26, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextFieldProvEmail)
                                        .addGroup(jSuppliersPanelLayout.createSequentialGroup()
                                            .addComponent(jTextFieldProvTel, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(0, 100, Short.MAX_VALUE)))))
                            .addGroup(jSuppliersPanelLayout.createSequentialGroup()
                                .addComponent(jLabel25, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldProvDir, javax.swing.GroupLayout.PREFERRED_SIZE, 309, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jSuppliersPanelLayout.createSequentialGroup()
                                .addComponent(jLabel28, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldProvWeb, javax.swing.GroupLayout.PREFERRED_SIZE, 397, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        jSuppliersPanelLayout.setVerticalGroup(
            jSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jSuppliersPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(jButtonEditarProveedor)
                    .addComponent(jButtonGuardarProveedor)
                    .addComponent(jButtonCancelarProveedor)
                    .addComponent(jButtonEliminarProveedor))
                .addGap(52, 52, 52)
                .addGroup(jSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNomSupplier, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel24, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldProvContacto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(4, 4, 4)
                .addGroup(jSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel25, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldProvDir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldProvTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel26, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldProvEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel27, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jSuppliersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel28, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldProvWeb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(50, Short.MAX_VALUE))
        );

        Center.add(jSuppliersPanel);
        jSuppliersPanel.setBounds(20, 20, 680, 288);

        jMatPrimaPanel.setBackground(new java.awt.Color(255, 255, 255));
        jMatPrimaPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(0, 0, 0)));

        jLabel13.setText("Nombre:");

        jTextFieldMatPrimaNom.setEditable(false);
        jTextFieldMatPrimaNom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldMatPrimaNomActionPerformed(evt);
            }
        });
        jTextFieldMatPrimaNom.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                jTextFieldMatPrimaNomInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        jTextFieldMatPrimaNom.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldMatPrimaNomKeyTyped(evt);
            }
        });

        jButtonEditarMatPrima.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEditarMatPrima.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEditarMatPrima.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEditarMatPrima.setText("Editar");
        jButtonEditarMatPrima.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditarMatPrimaActionPerformed(evt);
            }
        });

        jLabel14.setText("Unidad Medida:");

        jLabel19.setText("Cantidad:");

        jLabel20.setText("Precio $:");

        jTextFieldMatPrimaPrecio.setEditable(false);
        jTextFieldMatPrimaPrecio.setText("0.0");
        jTextFieldMatPrimaPrecio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldMatPrimaPrecioActionPerformed(evt);
            }
        });

        jTextFieldMatPrimaCant.setEditable(false);
        jTextFieldMatPrimaCant.setText("0.0");

        jButtonGuardarMatPrima.setBackground(new java.awt.Color(0, 153, 204));
        jButtonGuardarMatPrima.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonGuardarMatPrima.setForeground(new java.awt.Color(255, 255, 255));
        jButtonGuardarMatPrima.setText("Guardar");
        jButtonGuardarMatPrima.setEnabled(false);
        jButtonGuardarMatPrima.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarMatPrimaActionPerformed(evt);
            }
        });

        jLabel21.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel21.setText("MATERIA PRIMA");

        jButtonCancelarMatPrima.setBackground(new java.awt.Color(0, 153, 204));
        jButtonCancelarMatPrima.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonCancelarMatPrima.setForeground(new java.awt.Color(255, 255, 255));
        jButtonCancelarMatPrima.setText("Cancelar");
        jButtonCancelarMatPrima.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarMatPrimaActionPerformed(evt);
            }
        });

        jButtonEliminarMatPrima.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEliminarMatPrima.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEliminarMatPrima.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEliminarMatPrima.setText("Eliminar");
        jButtonEliminarMatPrima.setEnabled(false);
        jButtonEliminarMatPrima.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEliminarMatPrimaActionPerformed(evt);
            }
        });

        jComboBoxUniMedida.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Unitario", "Metro" }));

        javax.swing.GroupLayout jMatPrimaPanelLayout = new javax.swing.GroupLayout(jMatPrimaPanel);
        jMatPrimaPanel.setLayout(jMatPrimaPanelLayout);
        jMatPrimaPanelLayout.setHorizontalGroup(
            jMatPrimaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jMatPrimaPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jMatPrimaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jMatPrimaPanelLayout.createSequentialGroup()
                        .addGroup(jMatPrimaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel20, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel19, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel14, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jMatPrimaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jMatPrimaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jTextFieldMatPrimaCant, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jTextFieldMatPrimaPrecio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE))
                            .addComponent(jTextFieldMatPrimaNom, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBoxUniMedida, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(360, 360, Short.MAX_VALUE))
                    .addGroup(jMatPrimaPanelLayout.createSequentialGroup()
                        .addComponent(jLabel21)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 194, Short.MAX_VALUE)
                        .addComponent(jButtonEditarMatPrima)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonGuardarMatPrima)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonEliminarMatPrima)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonCancelarMatPrima)
                        .addGap(29, 29, 29))))
        );
        jMatPrimaPanelLayout.setVerticalGroup(
            jMatPrimaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jMatPrimaPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jMatPrimaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jMatPrimaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButtonEditarMatPrima)
                        .addComponent(jButtonGuardarMatPrima)
                        .addComponent(jButtonCancelarMatPrima)
                        .addComponent(jButtonEliminarMatPrima))
                    .addComponent(jLabel21))
                .addGap(52, 52, 52)
                .addGroup(jMatPrimaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldMatPrimaNom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jMatPrimaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxUniMedida, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jMatPrimaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel19, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldMatPrimaCant, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jMatPrimaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldMatPrimaPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        Center.add(jMatPrimaPanel);
        jMatPrimaPanel.setBounds(20, 20, 680, 225);

        jOrdersPanel.setBackground(new java.awt.Color(255, 255, 255));
        jOrdersPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(0, 0, 0)));
        jOrdersPanel.setPreferredSize(new java.awt.Dimension(680, 530));

        jLabel22.setText("Proveedor:");

        jButtonEditOrder.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEditOrder.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEditOrder.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEditOrder.setText("Editar");
        jButtonEditOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditOrderActionPerformed(evt);
            }
        });

        jButtonGuardarOrder.setBackground(new java.awt.Color(0, 153, 204));
        jButtonGuardarOrder.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonGuardarOrder.setForeground(new java.awt.Color(255, 255, 255));
        jButtonGuardarOrder.setText("Guardar");
        jButtonGuardarOrder.setEnabled(false);
        jButtonGuardarOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarOrderActionPerformed(evt);
            }
        });

        jLabel34.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel34.setText("COMPRAS");

        jButtonCancelarOrder.setBackground(new java.awt.Color(0, 153, 204));
        jButtonCancelarOrder.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonCancelarOrder.setForeground(new java.awt.Color(255, 255, 255));
        jButtonCancelarOrder.setText("Cancelar");
        jButtonCancelarOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarOrderActionPerformed(evt);
            }
        });

        jButtonEliminarOrder.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEliminarOrder.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEliminarOrder.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEliminarOrder.setText("Eliminar");
        jButtonEliminarOrder.setEnabled(false);
        jButtonEliminarOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEliminarOrderActionPerformed(evt);
            }
        });

        jComboBoxProveedor.setEnabled(false);
        jComboBoxProveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxProveedorActionPerformed(evt);
            }
        });

        jLabel35.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel35.setText("Detalle Pedido");

        jLabel1.setText("Productos:");

        jTextFieldBuscarProd.setEditable(false);
        jTextFieldBuscarProd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldBuscarProdActionPerformed(evt);
            }
        });

        jButtonBuscarProductos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dieci/ui/find_1.jpg"))); // NOI18N
        jButtonBuscarProductos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarProductosActionPerformed(evt);
            }
        });
        jButtonBuscarProductos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButtonBuscarProductosKeyPressed(evt);
            }
        });

        jListProductos.setEnabled(false);
        jListProductos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jListProductosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jListProductos);

        jTableProductosPedido.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jTableProductosPedido.setEnabled(false);
        jTableProductosPedido.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableProductosPedidoMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(jTableProductosPedido);

        jLabel29.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel29.setText("->");

        jLabel38.setText("Fecha:");

        jTextFieldOrderDate.setEnabled(false);

        jLabel31.setText("Total compra $:");

        javax.swing.GroupLayout jOrdersPanelLayout = new javax.swing.GroupLayout(jOrdersPanel);
        jOrdersPanel.setLayout(jOrdersPanelLayout);
        jOrdersPanelLayout.setHorizontalGroup(
            jOrdersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jOrdersPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jOrdersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jOrdersPanelLayout.createSequentialGroup()
                        .addComponent(jLabel34)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonEditOrder)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonGuardarOrder)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonEliminarOrder)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonCancelarOrder)
                        .addGap(29, 29, 29))
                    .addGroup(jOrdersPanelLayout.createSequentialGroup()
                        .addGroup(jOrdersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jOrdersPanelLayout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextFieldBuscarProd, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonBuscarProductos, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jOrdersPanelLayout.createSequentialGroup()
                                .addComponent(jLabel22, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(jOrdersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jComboBoxProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldOrderDate, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jOrdersPanelLayout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel29)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 323, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(106, 106, 106))
                    .addGroup(jOrdersPanelLayout.createSequentialGroup()
                        .addGroup(jOrdersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel35)
                            .addComponent(jLabel38)
                            .addGroup(jOrdersPanelLayout.createSequentialGroup()
                                .addComponent(jLabel31)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextFieldTotalOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        jOrdersPanelLayout.setVerticalGroup(
            jOrdersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jOrdersPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jOrdersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextFieldTotalOrder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jOrdersPanelLayout.createSequentialGroup()
                        .addGroup(jOrdersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jOrdersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButtonEditOrder)
                                .addComponent(jButtonGuardarOrder)
                                .addComponent(jButtonCancelarOrder)
                                .addComponent(jButtonEliminarOrder))
                            .addComponent(jLabel34))
                        .addGap(17, 17, 17)
                        .addGroup(jOrdersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel38)
                            .addComponent(jTextFieldOrderDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jOrdersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel22, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBoxProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel35)
                        .addGap(18, 18, 18)
                        .addGroup(jOrdersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jOrdersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel1)
                                .addComponent(jTextFieldBuscarProd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jButtonBuscarProductos, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jOrdersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jOrdersPanelLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jOrdersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE)))
                            .addGroup(jOrdersPanelLayout.createSequentialGroup()
                                .addGap(88, 88, 88)
                                .addComponent(jLabel29)))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel31)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        Center.add(jOrdersPanel);
        jOrdersPanel.setBounds(20, 20, 760, 540);

        jReturnsPanel.setBackground(new java.awt.Color(255, 255, 255));
        jReturnsPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(0, 0, 0)));
        jReturnsPanel.setPreferredSize(new java.awt.Dimension(680, 530));

        jButtonEditReturn.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEditReturn.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEditReturn.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEditReturn.setText("Editar");
        jButtonEditReturn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditReturnActionPerformed(evt);
            }
        });

        jButtonGuardarReturn.setBackground(new java.awt.Color(0, 153, 204));
        jButtonGuardarReturn.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonGuardarReturn.setForeground(new java.awt.Color(255, 255, 255));
        jButtonGuardarReturn.setText("Guardar");
        jButtonGuardarReturn.setEnabled(false);
        jButtonGuardarReturn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarReturnActionPerformed(evt);
            }
        });

        jLabel36.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel36.setText("DEVOLUCIONES");

        jButtonCancelarReturn.setBackground(new java.awt.Color(0, 153, 204));
        jButtonCancelarReturn.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonCancelarReturn.setForeground(new java.awt.Color(255, 255, 255));
        jButtonCancelarReturn.setText("Cancelar");
        jButtonCancelarReturn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarReturnActionPerformed(evt);
            }
        });

        jButtonEliminarReturn.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEliminarReturn.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEliminarReturn.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEliminarReturn.setText("Eliminar");
        jButtonEliminarReturn.setEnabled(false);
        jButtonEliminarReturn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEliminarReturnActionPerformed(evt);
            }
        });

        jLabel37.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel37.setText("Detalle devoluciones");

        jButtonBuscarPedidos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dieci/ui/find_1.jpg"))); // NOI18N
        jButtonBuscarPedidos.setEnabled(false);
        jButtonBuscarPedidos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarPedidosActionPerformed(evt);
            }
        });
        jButtonBuscarPedidos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButtonBuscarPedidosKeyPressed(evt);
            }
        });

        jListPedidos.setEnabled(false);
        jListPedidos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jListPedidosMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(jListPedidos);

        jTableProductosPedidosDevol.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jTableProductosPedidosDevol.setEnabled(false);
        jTableProductosPedidosDevol.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableProductosPedidosDevolMouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(jTableProductosPedidosDevol);

        jLabel32.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel32.setText("->");

        jLabel33.setText("Fecha:");

        buttonGroupOrdersSearch.add(jRadioButtonDateSearch);
        jRadioButtonDateSearch.setText("Fecha");
        jRadioButtonDateSearch.setEnabled(false);
        jRadioButtonDateSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonDateSearchActionPerformed(evt);
            }
        });

        buttonGroupOrdersSearch.add(jRadioButtonSupplierSearch);
        jRadioButtonSupplierSearch.setText("Proveedor");
        jRadioButtonSupplierSearch.setEnabled(false);
        jRadioButtonSupplierSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonSupplierSearchActionPerformed(evt);
            }
        });

        jLabelDateSince.setText("Desde:");

        jTextFieldReturnDate.setText(dia_2+"/"+mes_2+"/"+anio_2);
        jTextFieldDateSince.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldDateSinceActionPerformed(evt);
            }
        });

        jLabelDateTo.setText("Hasta:");

        jTextFieldReturnDate.setText(dia_3+"/"+mes_3+"/"+anio_3);

        jLabelSupplier.setText("Nombre:");

        jTextFieldSupplier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldSupplierActionPerformed(evt);
            }
        });

        jLabel30.setText("BUSCAR PEDIDOS REALIZADOS:");

        javax.swing.GroupLayout jReturnsPanelLayout = new javax.swing.GroupLayout(jReturnsPanel);
        jReturnsPanel.setLayout(jReturnsPanelLayout);
        jReturnsPanelLayout.setHorizontalGroup(
            jReturnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jReturnsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jReturnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jReturnsPanelLayout.createSequentialGroup()
                        .addGroup(jReturnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jReturnsPanelLayout.createSequentialGroup()
                                .addComponent(jLabelSupplier)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldSupplier, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(65, 65, 65)
                                .addComponent(jButtonBuscarPedidos, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jReturnsPanelLayout.createSequentialGroup()
                                .addComponent(jRadioButtonDateSearch)
                                .addGap(18, 18, 18)
                                .addComponent(jRadioButtonSupplierSearch)
                                .addGap(18, 18, 18)
                                .addComponent(jLabelDateSince)
                                .addGap(18, 18, 18)
                                .addComponent(jTextFieldDateSince, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(22, 22, 22)
                                .addComponent(jLabelDateTo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextFieldDateTo, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jReturnsPanelLayout.createSequentialGroup()
                                .addGap(88, 88, 88)
                                .addComponent(jTextFieldReturnDate, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jReturnsPanelLayout.createSequentialGroup()
                        .addGroup(jReturnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel33)
                            .addComponent(jLabel37)
                            .addComponent(jLabel30))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jReturnsPanelLayout.createSequentialGroup()
                        .addGroup(jReturnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jReturnsPanelLayout.createSequentialGroup()
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel32)
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                            .addGroup(jReturnsPanelLayout.createSequentialGroup()
                                .addComponent(jLabel36)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 278, Short.MAX_VALUE)
                                .addComponent(jButtonEditReturn)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonGuardarReturn)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonEliminarReturn)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonCancelarReturn)))
                        .addGap(29, 29, 29))))
        );
        jReturnsPanelLayout.setVerticalGroup(
            jReturnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jReturnsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jReturnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jReturnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButtonEditReturn)
                        .addComponent(jButtonGuardarReturn)
                        .addComponent(jButtonCancelarReturn)
                        .addComponent(jButtonEliminarReturn))
                    .addComponent(jLabel36))
                .addGap(24, 24, 24)
                .addGroup(jReturnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel33)
                    .addComponent(jTextFieldReturnDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel37)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel30)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jReturnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButtonDateSearch)
                    .addComponent(jRadioButtonSupplierSearch)
                    .addComponent(jLabelDateSince)
                    .addComponent(jTextFieldDateSince, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelDateTo)
                    .addComponent(jTextFieldDateTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(jReturnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonBuscarPedidos, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jReturnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabelSupplier)
                        .addComponent(jTextFieldSupplier, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jReturnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jReturnsPanelLayout.createSequentialGroup()
                        .addGap(77, 77, 77)
                        .addComponent(jLabel32))
                    .addGroup(jReturnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        Center.add(jReturnsPanel);
        jReturnsPanel.setBounds(20, 20, 760, 540);

        jSalesPanel.setBackground(new java.awt.Color(255, 255, 255));
        jSalesPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(0, 0, 0)));
        jSalesPanel.setPreferredSize(new java.awt.Dimension(680, 530));

        jLabel39.setText("Cliente:");

        jButtonEditSale.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEditSale.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEditSale.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEditSale.setText("Editar");
        jButtonEditSale.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditSaleActionPerformed(evt);
            }
        });

        jButtonGuardarSale.setBackground(new java.awt.Color(0, 153, 204));
        jButtonGuardarSale.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonGuardarSale.setForeground(new java.awt.Color(255, 255, 255));
        jButtonGuardarSale.setText("Guardar");
        jButtonGuardarSale.setEnabled(false);
        jButtonGuardarSale.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarSaleActionPerformed(evt);
            }
        });

        jLabel40.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel40.setText("VENTAS");

        jButtonCancelarSale.setBackground(new java.awt.Color(0, 153, 204));
        jButtonCancelarSale.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonCancelarSale.setForeground(new java.awt.Color(255, 255, 255));
        jButtonCancelarSale.setText("Cancelar");
        jButtonCancelarSale.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarSaleActionPerformed(evt);
            }
        });

        jButtonEliminarSale.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEliminarSale.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEliminarSale.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEliminarSale.setText("Eliminar");
        jButtonEliminarSale.setEnabled(false);
        jButtonEliminarSale.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEliminarSaleActionPerformed(evt);
            }
        });

        jComboBoxClient.setEnabled(false);
        jComboBoxClient.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxClientActionPerformed(evt);
            }
        });

        jLabel41.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel41.setText("Detalle Venta");

        jLabel42.setText("Productos:");

        jTextFieldBuscarProdSale.setEditable(false);
        jTextFieldBuscarProdSale.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldBuscarProdSaleActionPerformed(evt);
            }
        });

        jButtonBuscarProductosSale.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dieci/ui/find_1.jpg"))); // NOI18N
        jButtonBuscarProductosSale.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarProductosSaleActionPerformed(evt);
            }
        });
        jButtonBuscarProductosSale.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButtonBuscarProductosSaleKeyPressed(evt);
            }
        });

        jListProductosSale.setEnabled(false);
        jListProductosSale.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jListProductosSaleMouseClicked(evt);
            }
        });
        jScrollPane6.setViewportView(jListProductosSale);

        jTableProductosSale.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jTableProductosSale.setEnabled(false);
        jTableProductosSale.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableProductosSaleMouseClicked(evt);
            }
        });
        jScrollPane7.setViewportView(jTableProductosSale);

        jLabel43.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel43.setText("->");

        jLabel44.setText("Fecha:");

        jTextFieldSaleDate.setEditable(false);

        jLabel45.setText("Subtotal $:");

        jTextFieldSaleSubTotal.setEditable(false);
        jTextFieldSaleSubTotal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldSaleSubTotalActionPerformed(evt);
            }
        });

        buttonGroupDiscount.add(jRadioButtonPercentDisc);
        jRadioButtonPercentDisc.setText("%");
        jRadioButtonPercentDisc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonPercentDiscActionPerformed(evt);
            }
        });

        buttonGroupDiscount.add(jRadioButtonFixedDisc);
        jRadioButtonFixedDisc.setText("$");
        jRadioButtonFixedDisc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonFixedDiscActionPerformed(evt);
            }
        });

        jLabel46.setText("Descuento:");

        jTextFieldDiscountSale.setEditable(false);

        jLabel47.setText("TOTAL $:");

        jTextFieldTotalSale.setEditable(false);

        jButtonCalTotalSale.setText("Calcular");
        jButtonCalTotalSale.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCalTotalSaleActionPerformed(evt);
            }
        });

        jCheckBoxChargedSale.setBackground(new java.awt.Color(255, 255, 255));
        jCheckBoxChargedSale.setText("Cobrada");

        jCheckBoxDeliveredSale.setBackground(new java.awt.Color(255, 255, 255));
        jCheckBoxDeliveredSale.setText("Entregada");
        jCheckBoxDeliveredSale.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxDeliveredSaleActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jSalesPanelLayout = new javax.swing.GroupLayout(jSalesPanel);
        jSalesPanel.setLayout(jSalesPanelLayout);
        jSalesPanelLayout.setHorizontalGroup(
            jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jSalesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jSalesPanelLayout.createSequentialGroup()
                        .addGroup(jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jSalesPanelLayout.createSequentialGroup()
                                .addComponent(jLabel39, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jComboBoxClient, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldSaleDate, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jSalesPanelLayout.createSequentialGroup()
                                .addComponent(jLabel42)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextFieldBuscarProdSale, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonBuscarProductosSale, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jSalesPanelLayout.createSequentialGroup()
                        .addGroup(jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel41)
                            .addComponent(jLabel44))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jSalesPanelLayout.createSequentialGroup()
                        .addGroup(jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jSalesPanelLayout.createSequentialGroup()
                                .addComponent(jLabel45)
                                .addGap(18, 18, 18)
                                .addComponent(jTextFieldSaleSubTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(38, 38, 38)
                                .addComponent(jLabel46)
                                .addGap(18, 18, 18)
                                .addComponent(jRadioButtonPercentDisc)
                                .addGap(10, 10, 10)
                                .addComponent(jRadioButtonFixedDisc)
                                .addGap(18, 18, 18)
                                .addComponent(jTextFieldDiscountSale, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(29, 29, 29)
                                .addComponent(jButtonCalTotalSale)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel47)
                                .addGap(28, 28, 28)
                                .addComponent(jTextFieldTotalSale, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(jSalesPanelLayout.createSequentialGroup()
                                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel43)
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 386, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jSalesPanelLayout.createSequentialGroup()
                                .addComponent(jLabel40)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButtonEditSale)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonGuardarSale)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonEliminarSale)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonCancelarSale)))
                        .addGap(29, 29, 29))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jSalesPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBoxChargedSale)
                    .addComponent(jCheckBoxDeliveredSale))
                .addContainerGap())
        );
        jSalesPanelLayout.setVerticalGroup(
            jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jSalesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButtonEditSale)
                        .addComponent(jButtonGuardarSale)
                        .addComponent(jButtonCancelarSale)
                        .addComponent(jButtonEliminarSale))
                    .addComponent(jLabel40))
                .addGap(17, 17, 17)
                .addGroup(jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel44)
                    .addComponent(jTextFieldSaleDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(jLabel39, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jComboBoxClient))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel41)
                .addGap(18, 18, 18)
                .addGroup(jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel42)
                        .addComponent(jTextFieldBuscarProdSale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButtonBuscarProductosSale, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jSalesPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE)))
                    .addGroup(jSalesPanelLayout.createSequentialGroup()
                        .addGap(88, 88, 88)
                        .addComponent(jLabel43)))
                .addGap(1, 1, 1)
                .addComponent(jCheckBoxDeliveredSale)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jSalesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel45)
                    .addComponent(jTextFieldSaleSubTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel46)
                    .addComponent(jRadioButtonPercentDisc)
                    .addComponent(jRadioButtonFixedDisc)
                    .addComponent(jTextFieldDiscountSale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel47)
                    .addComponent(jTextFieldTotalSale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonCalTotalSale)
                    .addComponent(jCheckBoxChargedSale))
                .addContainerGap())
        );

        Center.add(jSalesPanel);
        jSalesPanel.setBounds(20, 20, 760, 570);

        jOrdersRawMaterialPanel.setBackground(new java.awt.Color(255, 255, 255));
        jOrdersRawMaterialPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(0, 0, 0)));
        jOrdersRawMaterialPanel.setPreferredSize(new java.awt.Dimension(680, 530));

        jLabel51.setText("Proveedor:");

        jButtonEditOrderRawMaterial.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEditOrderRawMaterial.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEditOrderRawMaterial.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEditOrderRawMaterial.setText("Editar");
        jButtonEditOrderRawMaterial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditOrderRawMaterialActionPerformed(evt);
            }
        });

        jButtonGuardarOrderRawMaterial.setBackground(new java.awt.Color(0, 153, 204));
        jButtonGuardarOrderRawMaterial.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonGuardarOrderRawMaterial.setForeground(new java.awt.Color(255, 255, 255));
        jButtonGuardarOrderRawMaterial.setText("Guardar");
        jButtonGuardarOrderRawMaterial.setEnabled(false);
        jButtonGuardarOrderRawMaterial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarOrderRawMaterialActionPerformed(evt);
            }
        });

        jLabel52.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel52.setText("COMPRAS MATERIA PRIMA");

        jButtonCancelarOrderRawMaterial.setBackground(new java.awt.Color(0, 153, 204));
        jButtonCancelarOrderRawMaterial.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonCancelarOrderRawMaterial.setForeground(new java.awt.Color(255, 255, 255));
        jButtonCancelarOrderRawMaterial.setText("Cancelar");
        jButtonCancelarOrderRawMaterial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarOrderRawMaterialActionPerformed(evt);
            }
        });

        jButtonEliminarOrderRawMaterial.setBackground(new java.awt.Color(0, 153, 204));
        jButtonEliminarOrderRawMaterial.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonEliminarOrderRawMaterial.setForeground(new java.awt.Color(255, 255, 255));
        jButtonEliminarOrderRawMaterial.setText("Eliminar");
        jButtonEliminarOrderRawMaterial.setEnabled(false);
        jButtonEliminarOrderRawMaterial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEliminarOrderRawMaterialActionPerformed(evt);
            }
        });

        jComboBoxProveedorRawMaterial.setEnabled(false);
        jComboBoxProveedorRawMaterial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxProveedorRawMaterialActionPerformed(evt);
            }
        });

        jLabel53.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel53.setText("Detalle Pedido");

        jLabel54.setText("Materia Prima:");

        jTextFieldBuscarRawMaterial.setEditable(false);
        jTextFieldBuscarRawMaterial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldBuscarRawMaterialActionPerformed(evt);
            }
        });

        jButtonBuscarRawMaterial.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dieci/ui/find_1.jpg"))); // NOI18N
        jButtonBuscarRawMaterial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarRawMaterialActionPerformed(evt);
            }
        });
        jButtonBuscarRawMaterial.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButtonBuscarRawMaterialKeyPressed(evt);
            }
        });

        jListRawMaterial.setEnabled(false);
        jListRawMaterial.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jListRawMaterialMouseClicked(evt);
            }
        });
        jScrollPane8.setViewportView(jListRawMaterial);

        jTableRawMaterialPedido.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jTableRawMaterialPedido.setEnabled(false);
        jTableRawMaterialPedido.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableRawMaterialPedidoMouseClicked(evt);
            }
        });
        jScrollPane9.setViewportView(jTableRawMaterialPedido);

        jLabel55.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel55.setText("->");

        jLabel56.setText("Fecha:");

        jTextFieldOrderRawMaterialDate.setEnabled(false);

        jLabel57.setText("Total compra $:");

        jOrderRawMaterialIDTextField.setToolTipText("");
        jOrderRawMaterialIDTextField.setEnabled(false);

        javax.swing.GroupLayout jOrdersRawMaterialPanelLayout = new javax.swing.GroupLayout(jOrdersRawMaterialPanel);
        jOrdersRawMaterialPanel.setLayout(jOrdersRawMaterialPanelLayout);
        jOrdersRawMaterialPanelLayout.setHorizontalGroup(
            jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jOrdersRawMaterialPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jOrdersRawMaterialPanelLayout.createSequentialGroup()
                        .addComponent(jLabel52)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jOrderRawMaterialIDTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonEditOrderRawMaterial)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonGuardarOrderRawMaterial)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonEliminarOrderRawMaterial)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonCancelarOrderRawMaterial)
                        .addGap(29, 29, 29))
                    .addGroup(jOrdersRawMaterialPanelLayout.createSequentialGroup()
                        .addGroup(jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jOrdersRawMaterialPanelLayout.createSequentialGroup()
                                .addComponent(jLabel54)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextFieldBuscarRawMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonBuscarRawMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jOrdersRawMaterialPanelLayout.createSequentialGroup()
                                .addComponent(jLabel51, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jComboBoxProveedorRawMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldOrderRawMaterialDate, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jOrdersRawMaterialPanelLayout.createSequentialGroup()
                        .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel55)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, 323, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(106, 106, 106))
                    .addGroup(jOrdersRawMaterialPanelLayout.createSequentialGroup()
                        .addGroup(jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel53)
                            .addComponent(jLabel56)
                            .addGroup(jOrdersRawMaterialPanelLayout.createSequentialGroup()
                                .addComponent(jLabel57)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextFieldTotalOrderRawMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        jOrdersRawMaterialPanelLayout.setVerticalGroup(
            jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jOrdersRawMaterialPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextFieldTotalOrderRawMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jOrdersRawMaterialPanelLayout.createSequentialGroup()
                        .addGroup(jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButtonEditOrderRawMaterial)
                                .addComponent(jButtonGuardarOrderRawMaterial)
                                .addComponent(jButtonCancelarOrderRawMaterial)
                                .addComponent(jButtonEliminarOrderRawMaterial))
                            .addGroup(jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel52)
                                .addComponent(jOrderRawMaterialIDTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(17, 17, 17)
                        .addGroup(jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel56)
                            .addComponent(jTextFieldOrderRawMaterialDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel51, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBoxProveedorRawMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel53)
                        .addGap(18, 18, 18)
                        .addGroup(jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel54)
                                .addComponent(jTextFieldBuscarRawMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jButtonBuscarRawMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jOrdersRawMaterialPanelLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jOrdersRawMaterialPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                                    .addComponent(jScrollPane8, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE)))
                            .addGroup(jOrdersRawMaterialPanelLayout.createSequentialGroup()
                                .addGap(88, 88, 88)
                                .addComponent(jLabel55)))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel57)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        Center.add(jOrdersRawMaterialPanel);
        jOrdersRawMaterialPanel.setBounds(20, 20, 760, 540);

        jPricePanel.setBackground(new java.awt.Color(255, 255, 255));
        jPricePanel.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(0, 0, 0)));
        jPricePanel.setPreferredSize(new java.awt.Dimension(680, 530));
        jPricePanel.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jPricePanelFocusLost(evt);
            }
        });

        jButtonGuardarPrecios.setBackground(new java.awt.Color(0, 153, 204));
        jButtonGuardarPrecios.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonGuardarPrecios.setForeground(new java.awt.Color(255, 255, 255));
        jButtonGuardarPrecios.setText("Guardar");
        jButtonGuardarPrecios.setEnabled(false);
        jButtonGuardarPrecios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarPreciosActionPerformed(evt);
            }
        });

        jLabel59.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel59.setText("ACTUALIZACION DE PRECIOS");

        jButtonCancelarPrecios.setBackground(new java.awt.Color(0, 153, 204));
        jButtonCancelarPrecios.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonCancelarPrecios.setForeground(new java.awt.Color(255, 255, 255));
        jButtonCancelarPrecios.setText("Cancelar");
        jButtonCancelarPrecios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarPreciosActionPerformed(evt);
            }
        });

        jLabel61.setText("Productos:");

        jTextFieldBuscarProdActualizar.setEditable(false);
        jTextFieldBuscarProdActualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldBuscarProdActualizarActionPerformed(evt);
            }
        });

        jButtonBuscarProductosActPrecio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dieci/ui/find_1.jpg"))); // NOI18N
        jButtonBuscarProductosActPrecio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarProductosActPrecioActionPerformed(evt);
            }
        });
        jButtonBuscarProductosActPrecio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButtonBuscarProductosActPrecioKeyPressed(evt);
            }
        });

        jListProductosActualizar.setEnabled(false);
        jListProductosActualizar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jListProductosActualizarMouseClicked(evt);
            }
        });
        jScrollPane10.setViewportView(jListProductosActualizar);

        jTableProductosNuevoPrecio.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jTableProductosNuevoPrecio.setEnabled(false);
        jTableProductosNuevoPrecio.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableProductosNuevoPrecioMouseClicked(evt);
            }
        });
        jScrollPane11.setViewportView(jTableProductosNuevoPrecio);

        jLabel62.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel62.setText("->");

        jLabel65.setText("Porcentaje %:");

        jIncreasePriceButton.setText("+");
        jIncreasePriceButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jIncreasePriceButtonActionPerformed(evt);
            }
        });

        jDecreasePriceButton.setText("-");
        jDecreasePriceButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jDecreasePriceButtonActionPerformed(evt);
            }
        });

        jLabel58.setText("Precio Fijo:");

        jOkNewPriceButton.setText("Ok");
        jOkNewPriceButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jOkNewPriceButtonActionPerformed(evt);
            }
        });

        jLabel63.setText("Seleccione uno o varios productos y un porcentaje de aumento o un monto fijo.");

        javax.swing.GroupLayout jPricePanelLayout = new javax.swing.GroupLayout(jPricePanel);
        jPricePanel.setLayout(jPricePanelLayout);
        jPricePanelLayout.setHorizontalGroup(
            jPricePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPricePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPricePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPricePanelLayout.createSequentialGroup()
                        .addGroup(jPricePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPricePanelLayout.createSequentialGroup()
                                .addComponent(jLabel61)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextFieldBuscarProdActualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel59))
                        .addGroup(jPricePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPricePanelLayout.createSequentialGroup()
                                .addGap(276, 276, 276)
                                .addComponent(jButtonGuardarPrecios)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonCancelarPrecios))
                            .addGroup(jPricePanelLayout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jButtonBuscarProductosActPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel65)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPorcentajePrecioTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jIncreasePriceButton, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jDecreasePriceButton, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel58)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jFixedNewPriceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jOkNewPriceButton, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPricePanelLayout.createSequentialGroup()
                        .addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel62)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 323, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel63, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 528, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(52, 52, 52))
        );
        jPricePanelLayout.setVerticalGroup(
            jPricePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPricePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPricePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPricePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButtonGuardarPrecios)
                        .addComponent(jButtonCancelarPrecios))
                    .addComponent(jLabel59))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel63)
                .addGap(18, 18, 18)
                .addGroup(jPricePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPricePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel61)
                        .addComponent(jTextFieldBuscarProdActualizar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPricePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPricePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel65)
                            .addComponent(jPorcentajePrecioTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jButtonBuscarProductosActPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPricePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jIncreasePriceButton)
                        .addComponent(jDecreasePriceButton)
                        .addComponent(jFixedNewPriceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jOkNewPriceButton))
                    .addComponent(jLabel58, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPricePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPricePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 299, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPricePanelLayout.createSequentialGroup()
                        .addGap(74, 74, 74)
                        .addComponent(jLabel62)))
                .addContainerGap(114, Short.MAX_VALUE))
        );

        Center.add(jPricePanel);
        jPricePanel.setBounds(20, 20, 760, 540);

        jImagenFondo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dieci/ui/dieci_image.jpg"))); // NOI18N
        jImagenFondo.setPreferredSize(new java.awt.Dimension(20, 20));
        Center.add(jImagenFondo);
        jImagenFondo.setBounds(200, 6, 1590, 670);

        getContentPane().add(Center, java.awt.BorderLayout.CENTER);
        Center.getAccessibleContext().setAccessibleName("");

        South.setBackground(new java.awt.Color(241, 245, 255));
        South.setPreferredSize(new java.awt.Dimension(1075, 50));

        javax.swing.GroupLayout SouthLayout = new javax.swing.GroupLayout(South);
        South.setLayout(SouthLayout);
        SouthLayout.setHorizontalGroup(
            SouthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1075, Short.MAX_VALUE)
        );
        SouthLayout.setVerticalGroup(
            SouthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 50, Short.MAX_VALUE)
        );

        getContentPane().add(South, java.awt.BorderLayout.SOUTH);
        South.getAccessibleContext().setAccessibleName("");

        West.setBackground(new java.awt.Color(241, 245, 255));

        jTabbedPane1.setBackground(new java.awt.Color(241, 245, 255));
        jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jTabbedPane1StateChanged(evt);
            }
        });

        jPanelProducts.setBackground(new java.awt.Color(255, 255, 255));

        jTableProducts.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTableProducts.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableProductsMouseClicked(evt);
            }
        });
        jTableProducts.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTableProductsPropertyChange(evt);
            }
        });
        jTableProducts.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTableProductsKeyPressed(evt);
            }
        });
        jScrollPaneProducts.setViewportView(jTableProducts);

        javax.swing.GroupLayout jPanelProductsLayout = new javax.swing.GroupLayout(jPanelProducts);
        jPanelProducts.setLayout(jPanelProductsLayout);
        jPanelProductsLayout.setHorizontalGroup(
            jPanelProductsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneProducts, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)
        );
        jPanelProductsLayout.setVerticalGroup(
            jPanelProductsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneProducts, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Productos", jPanelProducts);

        jPanelClients.setBackground(new java.awt.Color(255, 255, 255));
        jPanelClients.setPreferredSize(new java.awt.Dimension(389, 541));

        jTableClients.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTableClients.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableClientsMouseClicked(evt);
            }
        });
        jTableClients.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTableClientsPropertyChange(evt);
            }
        });
        jTableClients.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTableClientsKeyPressed(evt);
            }
        });
        jScrollPaneClients.setViewportView(jTableClients);

        javax.swing.GroupLayout jPanelClientsLayout = new javax.swing.GroupLayout(jPanelClients);
        jPanelClients.setLayout(jPanelClientsLayout);
        jPanelClientsLayout.setHorizontalGroup(
            jPanelClientsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneClients, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)
        );
        jPanelClientsLayout.setVerticalGroup(
            jPanelClientsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneClients, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Clientes", jPanelClients);

        jPanelSupplier.setBackground(new java.awt.Color(255, 255, 255));
        jPanelSupplier.setPreferredSize(new java.awt.Dimension(389, 541));

        jTableSuppliers.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTableSuppliers.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableSuppliersMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jTableSuppliersMouseEntered(evt);
            }
        });
        jTableSuppliers.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTableSuppliersPropertyChange(evt);
            }
        });
        jTableSuppliers.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTableSuppliersKeyPressed(evt);
            }
        });
        jScrollPaneSuppliers.setViewportView(jTableSuppliers);

        javax.swing.GroupLayout jPanelSupplierLayout = new javax.swing.GroupLayout(jPanelSupplier);
        jPanelSupplier.setLayout(jPanelSupplierLayout);
        jPanelSupplierLayout.setHorizontalGroup(
            jPanelSupplierLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneSuppliers, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)
        );
        jPanelSupplierLayout.setVerticalGroup(
            jPanelSupplierLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneSuppliers, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Proveedores", jPanelSupplier);

        jPanelMateriaPrima.setBackground(new java.awt.Color(255, 255, 255));

        jTableMatPrima.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTableMatPrima.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableMatPrimaMouseClicked(evt);
            }
        });
        jTableMatPrima.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTableMatPrimaPropertyChange(evt);
            }
        });
        jTableMatPrima.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTableMatPrimaKeyPressed(evt);
            }
        });
        jScrollPaneMatPrima.setViewportView(jTableMatPrima);

        javax.swing.GroupLayout jPanelMateriaPrimaLayout = new javax.swing.GroupLayout(jPanelMateriaPrima);
        jPanelMateriaPrima.setLayout(jPanelMateriaPrimaLayout);
        jPanelMateriaPrimaLayout.setHorizontalGroup(
            jPanelMateriaPrimaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneMatPrima, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)
        );
        jPanelMateriaPrimaLayout.setVerticalGroup(
            jPanelMateriaPrimaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneMatPrima, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Materia Prima", jPanelMateriaPrima);

        jPanelOrders.setBackground(new java.awt.Color(255, 255, 255));
        jPanelOrders.setPreferredSize(new java.awt.Dimension(389, 541));

        jTableOrders.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTableOrders.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableOrdersMouseClicked(evt);
            }
        });
        jTableOrders.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTableOrdersPropertyChange(evt);
            }
        });
        jTableOrders.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTableOrdersKeyPressed(evt);
            }
        });
        jScrollPaneOrders.setViewportView(jTableOrders);

        javax.swing.GroupLayout jPanelOrdersLayout = new javax.swing.GroupLayout(jPanelOrders);
        jPanelOrders.setLayout(jPanelOrdersLayout);
        jPanelOrdersLayout.setHorizontalGroup(
            jPanelOrdersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneOrders, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)
        );
        jPanelOrdersLayout.setVerticalGroup(
            jPanelOrdersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneOrders, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Compras Proveedores", jPanelOrders);

        jPanelReturns.setBackground(new java.awt.Color(255, 255, 255));
        jPanelReturns.setPreferredSize(new java.awt.Dimension(389, 541));

        jTableReturns.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTableReturns.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableReturnsMouseClicked(evt);
            }
        });
        jTableReturns.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTableReturnsPropertyChange(evt);
            }
        });
        jTableReturns.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTableReturnsKeyPressed(evt);
            }
        });
        jScrollPaneReturns.setViewportView(jTableReturns);

        javax.swing.GroupLayout jPanelReturnsLayout = new javax.swing.GroupLayout(jPanelReturns);
        jPanelReturns.setLayout(jPanelReturnsLayout);
        jPanelReturnsLayout.setHorizontalGroup(
            jPanelReturnsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneReturns, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)
        );
        jPanelReturnsLayout.setVerticalGroup(
            jPanelReturnsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneReturns, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Devoluciones", jPanelReturns);

        jPanelSales.setBackground(new java.awt.Color(255, 255, 255));
        jPanelSales.setPreferredSize(new java.awt.Dimension(389, 541));

        jTableSales.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTableSales.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableSalesMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jTableSalesMouseEntered(evt);
            }
        });
        jTableSales.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTableSalesPropertyChange(evt);
            }
        });
        jTableSales.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTableSalesKeyPressed(evt);
            }
        });
        jScrollPaneSales.setViewportView(jTableSales);

        javax.swing.GroupLayout jPanelSalesLayout = new javax.swing.GroupLayout(jPanelSales);
        jPanelSales.setLayout(jPanelSalesLayout);
        jPanelSalesLayout.setHorizontalGroup(
            jPanelSalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneSales, javax.swing.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE)
        );
        jPanelSalesLayout.setVerticalGroup(
            jPanelSalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneSales, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Ventas", jPanelSales);

        jPanelOrdersRawMaterial.setBackground(new java.awt.Color(255, 255, 255));
        jPanelOrdersRawMaterial.setPreferredSize(new java.awt.Dimension(389, 541));

        jTableOrdersRawMaterial.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTableOrdersRawMaterial.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableOrdersRawMaterialMouseClicked(evt);
            }
        });
        jTableOrdersRawMaterial.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTableOrdersRawMaterialPropertyChange(evt);
            }
        });
        jTableOrdersRawMaterial.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTableOrdersRawMaterialKeyPressed(evt);
            }
        });
        jScrollPaneOrdersRawMaterial.setViewportView(jTableOrdersRawMaterial);

        javax.swing.GroupLayout jPanelOrdersRawMaterialLayout = new javax.swing.GroupLayout(jPanelOrdersRawMaterial);
        jPanelOrdersRawMaterial.setLayout(jPanelOrdersRawMaterialLayout);
        jPanelOrdersRawMaterialLayout.setHorizontalGroup(
            jPanelOrdersRawMaterialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneOrdersRawMaterial, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
        );
        jPanelOrdersRawMaterialLayout.setVerticalGroup(
            jPanelOrdersRawMaterialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneOrdersRawMaterial, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Compras Mat Prima", jPanelOrdersRawMaterial);

        javax.swing.GroupLayout WestLayout = new javax.swing.GroupLayout(West);
        West.setLayout(WestLayout);
        WestLayout.setHorizontalGroup(
            WestLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(WestLayout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(22, Short.MAX_VALUE))
        );
        WestLayout.setVerticalGroup(
            WestLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 587, Short.MAX_VALUE)
        );

        getContentPane().add(West, java.awt.BorderLayout.LINE_START);
        West.getAccessibleContext().setAccessibleName("");

        fileMenu.setMnemonic('f');
        fileMenu.setText("Inicio");

        openMenuItem.setMnemonic('o');
        openMenuItem.setText("Materia prima productos");
        openMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(openMenuItem);

        exitMenuItem.setMnemonic('x');
        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setMnemonic('h');
        helpMenu.setText("Reportes");

        contentsMenuItem.setMnemonic('c');
        contentsMenuItem.setText("Reportes");
        contentsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                contentsMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(contentsMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void jTextFieldArticuloActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextFieldArticuloActionPerformed
    {//GEN-HEADEREND:event_jTextFieldArticuloActionPerformed
    }//GEN-LAST:event_jTextFieldArticuloActionPerformed

    private void jTextFieldArticuloInputMethodTextChanged(java.awt.event.InputMethodEvent evt)//GEN-FIRST:event_jTextFieldArticuloInputMethodTextChanged
    {//GEN-HEADEREND:event_jTextFieldArticuloInputMethodTextChanged
    }//GEN-LAST:event_jTextFieldArticuloInputMethodTextChanged

    private void jTextFieldArticuloKeyTyped(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextFieldArticuloKeyTyped
    {//GEN-HEADEREND:event_jTextFieldArticuloKeyTyped
    }//GEN-LAST:event_jTextFieldArticuloKeyTyped

    private void jButtonEditProductActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEditProductActionPerformed
    {//GEN-HEADEREND:event_jButtonEditProductActionPerformed
        setProductFieldsEditable(true);
        this.jButtonEditProduct.setEnabled(false);
        this.jButtonGuardarProducto.setEnabled(true);
        this.jButtonEliminarProducto.setEnabled(true);
        this.jTextFieldArticulo.requestFocusInWindow();
    }//GEN-LAST:event_jButtonEditProductActionPerformed

    private void jButtonCancelarProductoActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonCancelarProductoActionPerformed
    {//GEN-HEADEREND:event_jButtonCancelarProductoActionPerformed
        this.jProductsPanel.setVisible(false);
    }//GEN-LAST:event_jButtonCancelarProductoActionPerformed

    private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_jTabbedPane1StateChanged
    {//GEN-HEADEREND:event_jTabbedPane1StateChanged
        setAllPanelsInvisible();

        if (this.jTabbedPane1.getSelectedIndex() == 0) {
            //products
        }
        else if (this.jTabbedPane1.getSelectedIndex() == 1) {
            //clientes
        }
        else if (this.jTabbedPane1.getSelectedIndex() == 2) {
            //proveedores
        }
    }//GEN-LAST:event_jTabbedPane1StateChanged

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
        if (this.jTabbedPane1.getSelectedIndex() == 0) {
            //products
            this.jProductsPanel.setVisible(true);

            dataProductFormClean();
            setProductFieldsEditable(true);

            this.jButtonEditProduct.setEnabled(false);
            this.jButtonGuardarProducto.setEnabled(true);
            this.jButtonEliminarProducto.setEnabled(false);
            this.jTextFieldArticulo.requestFocusInWindow();
            this.jPricePanel.setVisible(false);
        }
        else if (this.jTabbedPane1.getSelectedIndex() == 1) {
            //clientes
            this.jClientesPanel.setVisible(true);
            dataClientFormClean();
            setClientFieldsEditable(true);

            this.jButtonEditarCliente.setEnabled(false);
            this.jButtonGuardarCliente.setEnabled(true);
            this.jButtonEliminarCliente.setEnabled(false);
            this.jTextFieldNomCliente.requestFocusInWindow();
            this.jPricePanel.setVisible(false);
        }
        else if (this.jTabbedPane1.getSelectedIndex() == 2) {
            //proveedores
            this.jSuppliersPanel.setVisible(true);
            dataSupplierFormClean();
            setSupplierFieldsEditable(true);

            this.jButtonEditarProveedor.setEnabled(false);
            this.jButtonGuardarProveedor.setEnabled(true);
            this.jButtonEliminarProveedor.setEnabled(false);
            this.jTextFieldNomSupplier.requestFocusInWindow();
            this.jPricePanel.setVisible(false);
        }
        else if (this.jTabbedPane1.getSelectedIndex() == 3) {
            //mat prima
            this.jMatPrimaPanel.setVisible(true);
            dataMatPrimaFormClean();
            setMatPrimaFieldsEditable(true);

            this.jButtonEditarMatPrima.setEnabled(false);
            this.jButtonGuardarMatPrima.setEnabled(true);
            this.jButtonEliminarMatPrima.setEnabled(false);
            this.jTextFieldMatPrimaNom.requestFocusInWindow();
            this.jPricePanel.setVisible(false);
        }
        else if (this.jTabbedPane1.getSelectedIndex() == 4) {
            //orders
            this.jOrdersPanel.setVisible(true);
            fillSupplierComboBox();
            
            this.jTableProductosPedido.setModel(getProductsOrderListModel());
            this.jTableProductosPedido.getColumnModel().getColumn(0).setPreferredWidth(70);
            this.jTableProductosPedido.getColumnModel().getColumn(1).setPreferredWidth(10);
            
            dataOrderFormClean();
            setOrderFieldsEditable(true);

            this.jButtonEditOrder.setEnabled(false);
            this.jButtonGuardarOrder.setEnabled(true);
            this.jButtonEliminarOrder.setEnabled(false);
            this.jTextFieldOrderDate.requestFocusInWindow();
            this.jPricePanel.setVisible(false);
        }
        else if (this.jTabbedPane1.getSelectedIndex() == 5) {
            //returns
            this.jPricePanel.setVisible(false);
            if (jTableOrders.getModel().getRowCount() > 0) {
                this.jReturnsPanel.setVisible(true);
                
                setOrderSearchFieldsVisible(false);
                
                dataReturnFormClean();
                setReturnFieldsEditable(true);

                this.jButtonEditReturn.setEnabled(false);
                this.jButtonGuardarReturn.setEnabled(true);
                this.jButtonEliminarReturn.setEnabled(false);

                this.jTextFieldReturnDate.requestFocusInWindow();
            }
            else {
                JOptionPane.showMessageDialog(null, "No existen compras realizadas");
            }
            
        }
        else if (this.jTabbedPane1.getSelectedIndex() == 6) {
            //sales
            this.jPricePanel.setVisible(false);
            this.jSalesPanel.setVisible(true);
            fillClientsComboBox();
            
            this.jTableProductosSale.setModel(getProductsSaleListModel());
            this.jTableProductosSale.getColumnModel().getColumn(0).setPreferredWidth(70);
            this.jTableProductosSale.getColumnModel().getColumn(1).setPreferredWidth(10);
            
            dataSaleFormClean();
            setSaleFieldsEditable(true);

            this.jButtonEditSale.setEnabled(false);
            this.jButtonGuardarSale.setEnabled(true);
            this.jButtonEliminarSale.setEnabled(false);
            this.jTextFieldSaleDate.requestFocusInWindow();
        }
        else if (this.jTabbedPane1.getSelectedIndex() == 7) {
            //orders raw material
            this.jPricePanel.setVisible(false);
            this.jOrdersRawMaterialPanel.setVisible(true);
            fillSupplierComboBoxRawMaterial();
            
            this.jTableRawMaterialPedido.setModel(getRawMaterialOrderListModel());
            this.jTableRawMaterialPedido.getColumnModel().getColumn(0).setPreferredWidth(70);
            this.jTableRawMaterialPedido.getColumnModel().getColumn(1).setPreferredWidth(10);
            
            dataOrderRawMaterialFormClean();
            this.jOrderRawMaterialIDTextField.setVisible(false);
            setOrderRawMaterialFieldsEditable(true);

            this.jButtonEditOrderRawMaterial.setEnabled(false);
            this.jButtonGuardarOrderRawMaterial.setEnabled(true);
            this.jButtonEliminarOrderRawMaterial.setEnabled(false);
            this.jTextFieldOrderRawMaterialDate.requestFocusInWindow();
        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jTextFieldNomClienteActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextFieldNomClienteActionPerformed
    {//GEN-HEADEREND:event_jTextFieldNomClienteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldNomClienteActionPerformed

    private void jTextFieldNomClienteInputMethodTextChanged(java.awt.event.InputMethodEvent evt)//GEN-FIRST:event_jTextFieldNomClienteInputMethodTextChanged
    {//GEN-HEADEREND:event_jTextFieldNomClienteInputMethodTextChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldNomClienteInputMethodTextChanged

    private void jTextFieldNomClienteKeyTyped(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextFieldNomClienteKeyTyped
    {//GEN-HEADEREND:event_jTextFieldNomClienteKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldNomClienteKeyTyped

    private void jButtonEditarClienteActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEditarClienteActionPerformed
    {//GEN-HEADEREND:event_jButtonEditarClienteActionPerformed
        setClientFieldsEditable(true);
    }//GEN-LAST:event_jButtonEditarClienteActionPerformed

    private void jButtonCancelarClienteActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonCancelarClienteActionPerformed
    {//GEN-HEADEREND:event_jButtonCancelarClienteActionPerformed
        this.jClientesPanel.setVisible(false);
    }//GEN-LAST:event_jButtonCancelarClienteActionPerformed

    private void jButtonGuardarProductoActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonGuardarProductoActionPerformed
    {//GEN-HEADEREND:event_jButtonGuardarProductoActionPerformed
        try {
            createOrSaveProduct();
            setProductFieldsEditable(false);
            this.jButtonEditProduct.setEnabled(true);
            this.jButtonEliminarProducto.setEnabled(true);
            jTableProducts.setModel(getProductsListModel());
            this.jProductsPanel.setVisible(false);
        }
        catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
        
    }//GEN-LAST:event_jButtonGuardarProductoActionPerformed

    private void jTableProductsMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jTableProductsMouseClicked
    {//GEN-HEADEREND:event_jTableProductsMouseClicked
        if (evt.getClickCount() == 2)
        {
            setProductData();
            
        }
    }//GEN-LAST:event_jTableProductsMouseClicked

    private void jTableProductsPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_jTableProductsPropertyChange
    {//GEN-HEADEREND:event_jTableProductsPropertyChange
        
    }//GEN-LAST:event_jTableProductsPropertyChange

    private void jTextAreaDescKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextAreaDescKeyPressed
    {//GEN-HEADEREND:event_jTextAreaDescKeyPressed
        
    }//GEN-LAST:event_jTextAreaDescKeyPressed

    private void jButtonEliminarProductoActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEliminarProductoActionPerformed
    {//GEN-HEADEREND:event_jButtonEliminarProductoActionPerformed
        deleteProduct();
        dataProductFormClean();
        setProductFieldsEditable(true);
        this.jButtonEditProduct.setEnabled(false);
        this.jButtonEliminarProducto.setEnabled(false);
        this.jButtonGuardarProducto.setEnabled(true);
        jTableProducts.setModel(getProductsListModel());
    }//GEN-LAST:event_jButtonEliminarProductoActionPerformed

                
    private void jTableClientsMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jTableClientsMouseClicked
    {//GEN-HEADEREND:event_jTableClientsMouseClicked
        if (evt.getClickCount() == 2)
        {
            jClientesPanel.setVisible(true);
            getSelectedClientData();
            setClientFieldsEditable(false);
            jButtonEditarCliente.setEnabled(true);
            jButtonEliminarCliente.setEnabled(true);
            jButtonGuardarCliente.setEnabled(false);
        }
    }//GEN-LAST:event_jTableClientsMouseClicked

    private void jTableClientsPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_jTableClientsPropertyChange
    {//GEN-HEADEREND:event_jTableClientsPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jTableClientsPropertyChange

    private void jButtonGuardarClienteActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonGuardarClienteActionPerformed
    {//GEN-HEADEREND:event_jButtonGuardarClienteActionPerformed
        try {
            createOrSaveClient();
            setClientFieldsEditable(false);
            this.jButtonEditarCliente.setEnabled(true);
            this.jButtonEliminarCliente.setEnabled(true);
            jTableClients.setModel(getClientsListModel());
            this.jClientesPanel.setVisible(false);
        }
        catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
    }//GEN-LAST:event_jButtonGuardarClienteActionPerformed

    private void jButtonEliminarClienteActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEliminarClienteActionPerformed
    {//GEN-HEADEREND:event_jButtonEliminarClienteActionPerformed
        deleteClient();
        dataClientFormClean();
        setClientFieldsEditable(true);
        this.jButtonEditarCliente.setEnabled(false);
        this.jButtonEliminarCliente.setEnabled(false);
        this.jButtonGuardarCliente.setEnabled(true);
        jTableClients.setModel(getClientsListModel());
    }//GEN-LAST:event_jButtonEliminarClienteActionPerformed

    private void jTableSuppliersMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jTableSuppliersMouseClicked
    {//GEN-HEADEREND:event_jTableSuppliersMouseClicked
        if (evt.getClickCount() == 2)
        {
            jSuppliersPanel.setVisible(true);
            getSelectedSupplierData();
            setSupplierFieldsEditable(false);
            jButtonEditarProveedor.setEnabled(true);
            jButtonEliminarProveedor.setEnabled(true);
            jButtonGuardarProveedor.setEnabled(false);
        }
    }//GEN-LAST:event_jTableSuppliersMouseClicked

    private void jTableSuppliersPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_jTableSuppliersPropertyChange
    {//GEN-HEADEREND:event_jTableSuppliersPropertyChange
        
    }//GEN-LAST:event_jTableSuppliersPropertyChange

    private void jTextFieldNomSupplierActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextFieldNomSupplierActionPerformed
    {//GEN-HEADEREND:event_jTextFieldNomSupplierActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldNomSupplierActionPerformed

    private void jTextFieldNomSupplierInputMethodTextChanged(java.awt.event.InputMethodEvent evt)//GEN-FIRST:event_jTextFieldNomSupplierInputMethodTextChanged
    {//GEN-HEADEREND:event_jTextFieldNomSupplierInputMethodTextChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldNomSupplierInputMethodTextChanged

    private void jTextFieldNomSupplierKeyTyped(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextFieldNomSupplierKeyTyped
    {//GEN-HEADEREND:event_jTextFieldNomSupplierKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldNomSupplierKeyTyped

    private void jButtonEditarProveedorActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEditarProveedorActionPerformed
    {//GEN-HEADEREND:event_jButtonEditarProveedorActionPerformed
        this.jButtonGuardarProveedor.setEnabled(true);
        setSupplierFieldsEditable(true);
    }//GEN-LAST:event_jButtonEditarProveedorActionPerformed

    private void jButtonGuardarProveedorActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonGuardarProveedorActionPerformed
    {//GEN-HEADEREND:event_jButtonGuardarProveedorActionPerformed
        try {
            createOrSaveSupplier();
            setSupplierFieldsEditable(false);
            this.jButtonEditarProveedor.setEnabled(true);
            this.jButtonEliminarProveedor.setEnabled(true);
            jTableSuppliers.setModel(getSuppliersListModel());
            this.jSuppliersPanel.setVisible(false);
        }
        catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
    }//GEN-LAST:event_jButtonGuardarProveedorActionPerformed

    private void jButtonCancelarProveedorActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonCancelarProveedorActionPerformed
    {//GEN-HEADEREND:event_jButtonCancelarProveedorActionPerformed
        this.jSuppliersPanel.setVisible(false);
    }//GEN-LAST:event_jButtonCancelarProveedorActionPerformed

    private void jButtonEliminarProveedorActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEliminarProveedorActionPerformed
    {//GEN-HEADEREND:event_jButtonEliminarProveedorActionPerformed
        try {
            deleteSupplier();
            dataSupplierFormClean();
            setSupplierFieldsEditable(true);
            this.jButtonEditarProveedor.setEnabled(false);
            this.jButtonEliminarProveedor.setEnabled(false);
            this.jButtonGuardarProveedor.setEnabled(true);
            jTableSuppliers.setModel(getSuppliersListModel());
            this.jSuppliersPanel.setVisible(false);
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }
        
    }//GEN-LAST:event_jButtonEliminarProveedorActionPerformed

    private void jTableSuppliersMouseEntered(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jTableSuppliersMouseEntered
    {//GEN-HEADEREND:event_jTableSuppliersMouseEntered
        // TODO add your handling code here:
    }//GEN-LAST:event_jTableSuppliersMouseEntered

    private void jTableMatPrimaMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jTableMatPrimaMouseClicked
    {//GEN-HEADEREND:event_jTableMatPrimaMouseClicked
        if (evt.getClickCount() == 2)
        {
            selectMateriaPrima();
            
        }
    }//GEN-LAST:event_jTableMatPrimaMouseClicked

    private void jTableMatPrimaPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_jTableMatPrimaPropertyChange
    {//GEN-HEADEREND:event_jTableMatPrimaPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jTableMatPrimaPropertyChange

    private void jTextFieldMatPrimaNomActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextFieldMatPrimaNomActionPerformed
    {//GEN-HEADEREND:event_jTextFieldMatPrimaNomActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldMatPrimaNomActionPerformed

    private void jTextFieldMatPrimaNomInputMethodTextChanged(java.awt.event.InputMethodEvent evt)//GEN-FIRST:event_jTextFieldMatPrimaNomInputMethodTextChanged
    {//GEN-HEADEREND:event_jTextFieldMatPrimaNomInputMethodTextChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldMatPrimaNomInputMethodTextChanged

    private void jTextFieldMatPrimaNomKeyTyped(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextFieldMatPrimaNomKeyTyped
    {//GEN-HEADEREND:event_jTextFieldMatPrimaNomKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldMatPrimaNomKeyTyped

    private void jButtonEditarMatPrimaActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEditarMatPrimaActionPerformed
    {//GEN-HEADEREND:event_jButtonEditarMatPrimaActionPerformed
        setMatPrimaFieldsEditable(true);
        this.jButtonEditarMatPrima.setEnabled(false);
        this.jButtonGuardarMatPrima.setEnabled(true);
        this.jButtonEliminarMatPrima.setEnabled(false);
    }//GEN-LAST:event_jButtonEditarMatPrimaActionPerformed

    private void jButtonGuardarMatPrimaActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonGuardarMatPrimaActionPerformed
    {//GEN-HEADEREND:event_jButtonGuardarMatPrimaActionPerformed
        try {
            createOrSaveMatPrima();
            setMatPrimaFieldsEditable(false);
            this.jButtonEditarMatPrima.setEnabled(true);
            this.jButtonEliminarMatPrima.setEnabled(true);
            jTableMatPrima.setModel(getMatPrimaListModel());
            this.jMatPrimaPanel.setVisible(false);
        }
        catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
    }//GEN-LAST:event_jButtonGuardarMatPrimaActionPerformed

    private void jButtonCancelarMatPrimaActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonCancelarMatPrimaActionPerformed
    {//GEN-HEADEREND:event_jButtonCancelarMatPrimaActionPerformed
        this.jMatPrimaPanel.setVisible(false);
    }//GEN-LAST:event_jButtonCancelarMatPrimaActionPerformed

    private void jButtonEliminarMatPrimaActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEliminarMatPrimaActionPerformed
    {//GEN-HEADEREND:event_jButtonEliminarMatPrimaActionPerformed
        deleteMatPrima();
        dataMatPrimaFormClean();
        setMatPrimaFieldsEditable(true);
        this.jButtonEditarMatPrima.setEnabled(false);
        this.jButtonEliminarMatPrima.setEnabled(false);
        this.jButtonGuardarMatPrima.setEnabled(true);
        jTableMatPrima.setModel(getMatPrimaListModel());
    }//GEN-LAST:event_jButtonEliminarMatPrimaActionPerformed

    private void jTableProductsKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTableProductsKeyPressed
    {//GEN-HEADEREND:event_jTableProductsKeyPressed
        if(evt.getKeyCode() == evt.VK_ENTER)
        {
            setProductData();
        }
    }//GEN-LAST:event_jTableProductsKeyPressed

    private void jTableClientsKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTableClientsKeyPressed
    {//GEN-HEADEREND:event_jTableClientsKeyPressed
        if (evt.getKeyCode()== evt.VK_ENTER)
        {
            jClientesPanel.setVisible(true);
            getSelectedClientData();
            setClientFieldsEditable(false);
            jButtonEditarCliente.setEnabled(true);
            jButtonEliminarCliente.setEnabled(true);
            jButtonGuardarCliente.setEnabled(false);
        }
    }//GEN-LAST:event_jTableClientsKeyPressed

    private void jTableSuppliersKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTableSuppliersKeyPressed
    {//GEN-HEADEREND:event_jTableSuppliersKeyPressed
        if(evt.getKeyCode() == evt.VK_ENTER)
        {
            jSuppliersPanel.setVisible(true);
            getSelectedSupplierData();
            setSupplierFieldsEditable(false);
            jButtonEditarProveedor.setEnabled(true);
            jButtonEliminarProveedor.setEnabled(true);
            jButtonGuardarProveedor.setEnabled(false);
        }
    }//GEN-LAST:event_jTableSuppliersKeyPressed

    private void jTableMatPrimaKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTableMatPrimaKeyPressed
    {//GEN-HEADEREND:event_jTableMatPrimaKeyPressed
        if (evt.getKeyCode()== evt.VK_ENTER)
        {
            selectMateriaPrima();
        }
    }//GEN-LAST:event_jTableMatPrimaKeyPressed

    private void jTextFieldClienteContactoActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextFieldClienteContactoActionPerformed
    {//GEN-HEADEREND:event_jTextFieldClienteContactoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldClienteContactoActionPerformed

    private void jTextFieldClienteContactoInputMethodTextChanged(java.awt.event.InputMethodEvent evt)//GEN-FIRST:event_jTextFieldClienteContactoInputMethodTextChanged
    {//GEN-HEADEREND:event_jTextFieldClienteContactoInputMethodTextChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldClienteContactoInputMethodTextChanged

    private void jTextFieldClienteContactoKeyTyped(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextFieldClienteContactoKeyTyped
    {//GEN-HEADEREND:event_jTextFieldClienteContactoKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldClienteContactoKeyTyped

    private void jTextFieldClienteDirActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextFieldClienteDirActionPerformed
    {//GEN-HEADEREND:event_jTextFieldClienteDirActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldClienteDirActionPerformed

    private void jTextFieldClienteDirInputMethodTextChanged(java.awt.event.InputMethodEvent evt)//GEN-FIRST:event_jTextFieldClienteDirInputMethodTextChanged
    {//GEN-HEADEREND:event_jTextFieldClienteDirInputMethodTextChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldClienteDirInputMethodTextChanged

    private void jTextFieldClienteDirKeyTyped(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextFieldClienteDirKeyTyped
    {//GEN-HEADEREND:event_jTextFieldClienteDirKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldClienteDirKeyTyped

    private void jTextFieldClienteWebActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextFieldClienteWebActionPerformed
    {//GEN-HEADEREND:event_jTextFieldClienteWebActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldClienteWebActionPerformed

    private void jTextFieldClienteWebInputMethodTextChanged(java.awt.event.InputMethodEvent evt)//GEN-FIRST:event_jTextFieldClienteWebInputMethodTextChanged
    {//GEN-HEADEREND:event_jTextFieldClienteWebInputMethodTextChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldClienteWebInputMethodTextChanged

    private void jTextFieldClienteWebKeyTyped(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextFieldClienteWebKeyTyped
    {//GEN-HEADEREND:event_jTextFieldClienteWebKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldClienteWebKeyTyped

    private void jTextFieldProvContactoActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextFieldProvContactoActionPerformed
    {//GEN-HEADEREND:event_jTextFieldProvContactoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldProvContactoActionPerformed

    private void jTextFieldProvContactoInputMethodTextChanged(java.awt.event.InputMethodEvent evt)//GEN-FIRST:event_jTextFieldProvContactoInputMethodTextChanged
    {//GEN-HEADEREND:event_jTextFieldProvContactoInputMethodTextChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldProvContactoInputMethodTextChanged

    private void jTextFieldProvContactoKeyTyped(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextFieldProvContactoKeyTyped
    {//GEN-HEADEREND:event_jTextFieldProvContactoKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldProvContactoKeyTyped

    private void jTextFieldProvDirActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextFieldProvDirActionPerformed
    {//GEN-HEADEREND:event_jTextFieldProvDirActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldProvDirActionPerformed

    private void jTextFieldProvDirInputMethodTextChanged(java.awt.event.InputMethodEvent evt)//GEN-FIRST:event_jTextFieldProvDirInputMethodTextChanged
    {//GEN-HEADEREND:event_jTextFieldProvDirInputMethodTextChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldProvDirInputMethodTextChanged

    private void jTextFieldProvDirKeyTyped(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextFieldProvDirKeyTyped
    {//GEN-HEADEREND:event_jTextFieldProvDirKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldProvDirKeyTyped

    private void jTextFieldProvWebActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextFieldProvWebActionPerformed
    {//GEN-HEADEREND:event_jTextFieldProvWebActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldProvWebActionPerformed

    private void jTextFieldProvWebInputMethodTextChanged(java.awt.event.InputMethodEvent evt)//GEN-FIRST:event_jTextFieldProvWebInputMethodTextChanged
    {//GEN-HEADEREND:event_jTextFieldProvWebInputMethodTextChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldProvWebInputMethodTextChanged

    private void jTextFieldProvWebKeyTyped(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextFieldProvWebKeyTyped
    {//GEN-HEADEREND:event_jTextFieldProvWebKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldProvWebKeyTyped

    private void jTableOrdersMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jTableOrdersMouseClicked
    {//GEN-HEADEREND:event_jTableOrdersMouseClicked
        if (evt.getClickCount() == 2)
        {
            jOrdersPanel.setVisible(true);
            getSelectedOrderData();
            setOrderFieldsEditable(false);
            jButtonEditOrder.setEnabled(true);
            jButtonEliminarOrder.setEnabled(true);
            jButtonGuardarOrder.setEnabled(false);
        }
    }//GEN-LAST:event_jTableOrdersMouseClicked

    private void jTableOrdersPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_jTableOrdersPropertyChange
    {//GEN-HEADEREND:event_jTableOrdersPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jTableOrdersPropertyChange

    private void jTableOrdersKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTableOrdersKeyPressed
    {//GEN-HEADEREND:event_jTableOrdersKeyPressed
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){
            jOrdersPanel.setVisible(true);
            getSelectedOrderData();
            setOrderFieldsEditable(false);
            jButtonEditOrder.setEnabled(true);
            jButtonEliminarOrder.setEnabled(true);
            jButtonGuardarOrder.setEnabled(false);
        }
    }//GEN-LAST:event_jTableOrdersKeyPressed

    private void jButtonEditOrderActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEditOrderActionPerformed
    {//GEN-HEADEREND:event_jButtonEditOrderActionPerformed
        setOrderFieldsEditable(true);
        jButtonGuardarOrder.setEnabled(true);
        jButtonEditOrder.setEnabled(false);
    }//GEN-LAST:event_jButtonEditOrderActionPerformed

    private void jButtonGuardarOrderActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonGuardarOrderActionPerformed
    {//GEN-HEADEREND:event_jButtonGuardarOrderActionPerformed
        try {
            createOrSaveOrder();
            setOrderFieldsEditable(false);
            this.jButtonEditOrder.setEnabled(true);
            this.jButtonEliminarOrder.setEnabled(true);
            jTableOrders.setModel(getOrdersListModel());
            this.jOrdersPanel.setVisible(false);
        }
        catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
    }//GEN-LAST:event_jButtonGuardarOrderActionPerformed

    private void jButtonCancelarOrderActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonCancelarOrderActionPerformed
    {//GEN-HEADEREND:event_jButtonCancelarOrderActionPerformed
        this.jOrdersPanel.setVisible(false);
    }//GEN-LAST:event_jButtonCancelarOrderActionPerformed

    private void jButtonEliminarOrderActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEliminarOrderActionPerformed
    {//GEN-HEADEREND:event_jButtonEliminarOrderActionPerformed
        try {
            deleteOrder();
            dataOrderFormClean();
            setOrderFieldsEditable(true);
            this.jButtonEditOrder.setEnabled(false);
            this.jButtonEliminarOrder.setEnabled(false);
            this.jButtonGuardarOrder.setEnabled(true);
            jTableOrders.setModel(getOrdersListModel());
            jOrdersPanel.setVisible(false);
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }
        
    }//GEN-LAST:event_jButtonEliminarOrderActionPerformed

    private void jTextFieldBuscarProdActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextFieldBuscarProdActionPerformed
    {//GEN-HEADEREND:event_jTextFieldBuscarProdActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldBuscarProdActionPerformed

    private void jComboBoxProveedorActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jComboBoxProveedorActionPerformed
    {//GEN-HEADEREND:event_jComboBoxProveedorActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxProveedorActionPerformed

    private void jButtonBuscarProductosActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonBuscarProductosActionPerformed
    {//GEN-HEADEREND:event_jButtonBuscarProductosActionPerformed
        //find products
        findProducts();
    }//GEN-LAST:event_jButtonBuscarProductosActionPerformed

    private void jButtonBuscarProductosKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jButtonBuscarProductosKeyPressed
    {//GEN-HEADEREND:event_jButtonBuscarProductosKeyPressed
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){
            findProducts();
        }
    }//GEN-LAST:event_jButtonBuscarProductosKeyPressed

    private void jListProductosMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jListProductosMouseClicked
    {//GEN-HEADEREND:event_jListProductosMouseClicked
        if(evt.getClickCount() == 2){
            Product selected = (Product) jListProductos.getSelectedValue();
            double totalCost;
            if(jTextFieldTotalOrder.getText().isEmpty()){
                totalCost = 0;
            }else{
                totalCost = Double.valueOf(jTextFieldTotalOrder.getText());
            }
            totalCost+=selected.getCost();
                
            DefaultTableModel productsOrder = (DefaultTableModel) jTableProductosPedido.getModel();
            boolean newProduct = true;
            for (Iterator it = productsOrder.getDataVector().iterator(); it.hasNext();) {
                Vector object = (Vector) it.next();
                Product prod = (Product) object.get(0);
                if(prod.equals(selected)){
                    String value = (String) object.get(1);
                    int newCant = Integer.valueOf(value) + 1;
                    object.set(1, String.valueOf(newCant));
                    
                    double cost = Double.valueOf((String)object.get(2));
                    double newCost = prod.getCost()+cost;
                    object.set(2, String.valueOf(newCost));
                    newProduct = false;
                }                
            }
            if(newProduct){
                productsOrder.addRow(new Object[]{selected,"1",String.valueOf(selected.getCost())});
            }
            productsOrder.fireTableDataChanged();
            jTableProductosPedido.setModel(productsOrder);
            jTextFieldTotalOrder.setText(String.valueOf(Math.rint(totalCost)));
        }
    }//GEN-LAST:event_jListProductosMouseClicked

    private void jTableReturnsMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jTableReturnsMouseClicked
    {//GEN-HEADEREND:event_jTableReturnsMouseClicked
        if (evt.getClickCount() == 2)
        {
            setDataSelectedInReturnPanel();            
        }
        
    }//GEN-LAST:event_jTableReturnsMouseClicked

    private void jTableReturnsPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_jTableReturnsPropertyChange
    {//GEN-HEADEREND:event_jTableReturnsPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jTableReturnsPropertyChange

    private void jTableReturnsKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTableReturnsKeyPressed
    {//GEN-HEADEREND:event_jTableReturnsKeyPressed
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){
            setDataSelectedInReturnPanel();
        }
    }//GEN-LAST:event_jTableReturnsKeyPressed

    private void jButtonEditReturnActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEditReturnActionPerformed
    {//GEN-HEADEREND:event_jButtonEditReturnActionPerformed
        this.jTableProductosPedidosDevol.setEnabled(true);
        this.jButtonGuardarReturn.setEnabled(true);
        this.jButtonEditReturn.setEnabled(false);
        this.jButtonEliminarReturn.setEnabled(false);
    }//GEN-LAST:event_jButtonEditReturnActionPerformed

    private void jButtonGuardarReturnActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonGuardarReturnActionPerformed
    {//GEN-HEADEREND:event_jButtonGuardarReturnActionPerformed
        try {
            createOrUpdateReturn();
            setReturnFieldsEditable(false);
            this.jButtonEditReturn.setEnabled(true);
            this.jButtonGuardarReturn.setEnabled(false);
            this.jButtonEliminarReturn.setEnabled(true);
            jTableReturns.setModel(getReturnsListModel());
            this.jReturnsPanel.setVisible(false);
        }
        catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
    }//GEN-LAST:event_jButtonGuardarReturnActionPerformed

    private void jButtonCancelarReturnActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonCancelarReturnActionPerformed
    {//GEN-HEADEREND:event_jButtonCancelarReturnActionPerformed
        this.jReturnsPanel.setVisible(false);
    }//GEN-LAST:event_jButtonCancelarReturnActionPerformed

    private void jButtonEliminarReturnActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEliminarReturnActionPerformed
    {//GEN-HEADEREND:event_jButtonEliminarReturnActionPerformed
        try {
            deleteReturn();
            dataReturnFormClean();
            setReturnFieldsEditable(true);
            this.jButtonEditReturn.setEnabled(false);
            this.jButtonEliminarReturn.setEnabled(false);
            this.jButtonGuardarReturn.setEnabled(true);
            jTableReturns.setModel(getReturnsListModel());
            jReturnsPanel.setVisible(false);
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }
    }//GEN-LAST:event_jButtonEliminarReturnActionPerformed

    private void jButtonBuscarPedidosActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonBuscarPedidosActionPerformed
    {//GEN-HEADEREND:event_jButtonBuscarPedidosActionPerformed
        try 
        {
            findOrders();
        }
        catch (Exception ex) 
        {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
    }//GEN-LAST:event_jButtonBuscarPedidosActionPerformed

    private void jButtonBuscarPedidosKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jButtonBuscarPedidosKeyPressed
    {//GEN-HEADEREND:event_jButtonBuscarPedidosKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonBuscarPedidosKeyPressed

    private void jListPedidosMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jListPedidosMouseClicked
    {//GEN-HEADEREND:event_jListPedidosMouseClicked
        if(evt.getClickCount() == 2){
            Order selected = (Order) jListPedidos.getSelectedValue();
            
            DefaultTableModel productsOrder = (DefaultTableModel)getProductsOrderReturnsListModel();
            
            //get all products from order selected
            Set<OrderDetails> orderDetails = selected.getDetails();
            for (OrderDetails orderDetails1 : orderDetails) {
                Product product = productManager.findById(orderDetails1.getProductId());
                productsOrder.addRow(new Object[]{product,String.valueOf(orderDetails1.getAmount()),String.valueOf(0)});
            }
            
            //productsOrder.fireTableDataChanged();
            jTableProductosPedidosDevol.setModel(productsOrder);
            jTableProductosPedidosDevol.getColumnModel().getColumn(0).setPreferredWidth(100);
            jTableProductosPedidosDevol.getColumnModel().getColumn(1).setPreferredWidth(10);
            jTableProductosPedidosDevol.getColumnModel().getColumn(2).setPreferredWidth(10);
        }
    }//GEN-LAST:event_jListPedidosMouseClicked

    private void jButtonEditSaleActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEditSaleActionPerformed
    {//GEN-HEADEREND:event_jButtonEditSaleActionPerformed
        setSaleFieldsEditable(true);
        jButtonGuardarSale.setEnabled(true);
        jButtonEditSale.setEnabled(false);
    }//GEN-LAST:event_jButtonEditSaleActionPerformed

    private void jButtonGuardarSaleActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonGuardarSaleActionPerformed
    {//GEN-HEADEREND:event_jButtonGuardarSaleActionPerformed
        try {
            uISaleHandler.createOrSaveSale(getSaleData(), (DefaultTableModel) jTableProductosSale.getModel());
            setSaleFieldsEditable(false);
            this.jButtonEditSale.setEnabled(true);
            this.jButtonEliminarSale.setEnabled(true);
            jTableSales.setModel(uISaleHandler.getSalesListModel());
            this.jSalesPanel.setVisible(false);
        }
        catch(StockNotAvailableException e1){
            JOptionPane.showMessageDialog(null, e1.getMessage());
        }
        catch (Exception e2) {
            JOptionPane.showMessageDialog(null, e2.getMessage());
        }        
    }//GEN-LAST:event_jButtonGuardarSaleActionPerformed

    private void jButtonCancelarSaleActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonCancelarSaleActionPerformed
    {//GEN-HEADEREND:event_jButtonCancelarSaleActionPerformed
        this.jSalesPanel.setVisible(false);
    }//GEN-LAST:event_jButtonCancelarSaleActionPerformed

    private void jButtonEliminarSaleActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEliminarSaleActionPerformed
    {//GEN-HEADEREND:event_jButtonEliminarSaleActionPerformed
        try {
            deleteSale();
            dataSaleFormClean();
            setSaleFieldsEditable(true);
            this.jButtonEditSale.setEnabled(false);
            this.jButtonEliminarSale.setEnabled(false);
            this.jButtonGuardarSale.setEnabled(true);
            jTableSales.setModel(uISaleHandler.getSalesListModel());
            jSalesPanel.setVisible(false);
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }

    }//GEN-LAST:event_jButtonEliminarSaleActionPerformed

    private void jComboBoxClientActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jComboBoxClientActionPerformed
    {//GEN-HEADEREND:event_jComboBoxClientActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxClientActionPerformed

    private void jTextFieldBuscarProdSaleActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextFieldBuscarProdSaleActionPerformed
    {//GEN-HEADEREND:event_jTextFieldBuscarProdSaleActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldBuscarProdSaleActionPerformed

    private void jButtonBuscarProductosSaleActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonBuscarProductosSaleActionPerformed
    {//GEN-HEADEREND:event_jButtonBuscarProductosSaleActionPerformed
        //find products
        findProductsSale();
    }//GEN-LAST:event_jButtonBuscarProductosSaleActionPerformed

    private void jButtonBuscarProductosSaleKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jButtonBuscarProductosSaleKeyPressed
    {//GEN-HEADEREND:event_jButtonBuscarProductosSaleKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonBuscarProductosSaleKeyPressed

    private void jListProductosSaleMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jListProductosSaleMouseClicked
    {//GEN-HEADEREND:event_jListProductosSaleMouseClicked
        if (evt.getClickCount() == 2) 
        {
            Product selected = (Product) jListProductosSale.getSelectedValue();
            DefaultTableModel productsOrder = (DefaultTableModel) jTableProductosSale.getModel();
            boolean newProduct = true;
            ProductStock stock = stockManager.findByProductId(selected.getProductId());
            int stockAvailable = 0;
            if(stock != null){
                stockAvailable = stock.getAvailableAmount();
            }
            for (Iterator it = productsOrder.getDataVector().iterator(); it.hasNext();) {
                Vector object = (Vector) it.next();
                Product prod = (Product) object.get(0);
                if (prod.equals(selected)) {
                    String value = (String) object.get(1);
                    if(Integer.valueOf(value) < stockAvailable){
                        int newCant = Integer.valueOf(value) + 1;
                        object.set(1, String.valueOf(newCant));
                        object.set(2, String.valueOf(stockAvailable));
                    
                        double amount = Double.valueOf((String)object.get(3));
                        double price = (selected.getLatestProductPrice()!=null)?selected.getLatestProductPrice().getPriceValue():0;
                        amount +=price;
                        object.set(3, String.valueOf(amount));
                        
                        if (selected.getLatestProductPrice() != null) {
                            updateSubTotalSale(selected.getLatestProductPrice().getPriceValue(), Constants.ADD_OPERATION);
                        }
                    }                    
                    
                    newProduct = false;
                }
            }
            if (newProduct) {
                if (stockAvailable > 0) {
                    double price = (selected.getLatestProductPrice() != null) ? selected.getLatestProductPrice().getPriceValue() : 0;
                    productsOrder.addRow(new Object[]{selected, "1", String.valueOf(stockAvailable), String.valueOf(price)});

                    if (selected.getLatestProductPrice() != null) {
                        updateSubTotalSale(selected.getLatestProductPrice().getPriceValue(), Constants.ADD_OPERATION);
                    }
                }
            }
            productsOrder.fireTableDataChanged();
            jTableProductosSale.setModel(productsOrder);
            
                       
        }

    }//GEN-LAST:event_jListProductosSaleMouseClicked

    public void updateSubTotalSale(double amount, String operation)
    {
        String subTotal = this.jTextFieldSaleSubTotal.getText();
        double tot = Double.valueOf(subTotal);
        if(operation.equals(Constants.ADD_OPERATION))
        {
            tot+=amount;
        }
        else if(operation.equals(Constants.DELETE_OPERATION))
        {
            if(tot > 0){
                tot-=amount;
            }else{
                tot = 0;
            }            
        }
        
        this.jTextFieldSaleSubTotal.setText(String.valueOf(tot));
    }
    
    private void jTableSalesMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jTableSalesMouseClicked
    {//GEN-HEADEREND:event_jTableSalesMouseClicked
        if(evt.getClickCount() == 2){
           setDataSelectedInSalesPanel(); 
        }
    }//GEN-LAST:event_jTableSalesMouseClicked

    private void jTableSalesPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_jTableSalesPropertyChange
    {//GEN-HEADEREND:event_jTableSalesPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jTableSalesPropertyChange

    private void jTableSalesKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTableSalesKeyPressed
    {//GEN-HEADEREND:event_jTableSalesKeyPressed
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){
            setDataSelectedInSalesPanel();
        }
    }//GEN-LAST:event_jTableSalesKeyPressed

    private void jTextFieldSaleSubTotalActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextFieldSaleSubTotalActionPerformed
    {//GEN-HEADEREND:event_jTextFieldSaleSubTotalActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldSaleSubTotalActionPerformed

    private void jRadioButtonPercentDiscActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jRadioButtonPercentDiscActionPerformed
    {//GEN-HEADEREND:event_jRadioButtonPercentDiscActionPerformed
        if(jRadioButtonPercentDisc.isSelected()){
            jTextFieldDiscountSale.setEditable(true);
        }else{
            jTextFieldDiscountSale.setEditable(false);
        }
    }//GEN-LAST:event_jRadioButtonPercentDiscActionPerformed

    private void jButtonCalTotalSaleActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonCalTotalSaleActionPerformed
    {//GEN-HEADEREND:event_jButtonCalTotalSaleActionPerformed
        jTextFieldTotalSale.setText(String.valueOf(getTotalForSale()));        
        
    }//GEN-LAST:event_jButtonCalTotalSaleActionPerformed

    private void jRadioButtonSupplierSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonSupplierSearchActionPerformed
        if (this.jRadioButtonSupplierSearch.isSelected()) {
            this.jLabelDateSince.setVisible(false);
            this.jTextFieldDateSince.setVisible(false);
            this.jLabelDateTo.setVisible(false);
            this.jTextFieldDateTo.setVisible(false);
            this.jLabelSupplier.setVisible(true);
            this.jTextFieldSupplier.setVisible(true);
        }
    }//GEN-LAST:event_jRadioButtonSupplierSearchActionPerformed

    private void jTextFieldSupplierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldSupplierActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldSupplierActionPerformed

    private void jTextFieldDateSinceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldDateSinceActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldDateSinceActionPerformed

    private void jRadioButtonDateSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonDateSearchActionPerformed
        if (this.jRadioButtonDateSearch.isSelected()) {
            this.jLabelDateSince.setVisible(true);
            this.jTextFieldDateSince.setVisible(true);
            this.jLabelDateTo.setVisible(true);
            this.jTextFieldDateTo.setVisible(true);
            this.jLabelSupplier.setVisible(false);
            this.jTextFieldSupplier.setVisible(false);
        }
    }//GEN-LAST:event_jRadioButtonDateSearchActionPerformed

    private void jTableProductosSaleMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jTableProductosSaleMouseClicked
    {//GEN-HEADEREND:event_jTableProductosSaleMouseClicked
        if(evt.getClickCount() == 2)
        {
            //this is handled by the cell changed event of the table.
            
            
//            int selected = jTableProductosSale.getSelectedRow();
//            DefaultTableModel productsOrder = (DefaultTableModel) jTableProductosSale.getModel();
//            Vector object = (Vector)productsOrder.getDataVector().get(selected);
//            Product product = (Product) object.get(0);
//            String amount = (String) object.get(1);
//            if(Integer.valueOf(amount)>1)
//            {
//                int newAmount = Integer.valueOf(amount) - 1;
//                object.set(1, String.valueOf(newAmount));
//                double totalPrice = (double)object.get(2);
//                double price = (product.getLatestProductPrice()!=null)?product.getLatestProductPrice().getPriceValue():0;
//                totalPrice -=price;
//                object.set(2, totalPrice);
//            }
//            else
//            {
//                productsOrder.removeRow(selected);
//            }
//                
//            productsOrder.fireTableDataChanged();
//            
//            if(product.getLatestProductPrice()!=null)
//            {
//                updateSubTotalSale(product.getLatestProductPrice().getPriceValue(),Constants.DELETE_OPERATION);
//            }
        }
    }//GEN-LAST:event_jTableProductosSaleMouseClicked

    private void jTableProductosPedidosDevolMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jTableProductosPedidosDevolMouseClicked
    {//GEN-HEADEREND:event_jTableProductosPedidosDevolMouseClicked
        if(evt.getClickCount() == 2)
        {
            int selected = jTableProductosPedidosDevol.getSelectedRow();
            DefaultTableModel productsDevol = (DefaultTableModel) jTableProductosPedidosDevol.getModel();
            Vector object = (Vector)productsDevol.getDataVector().get(selected);
            String amountOrdered = (String) object.get(1);
            String amount = (String) object.get(2);
            int ordered= Integer.valueOf(amountOrdered);
            int returnValue = Integer.valueOf(amount);
            int newAmount = returnValue;
            if(returnValue < ordered){
                newAmount++;
            }
            object.set(2, String.valueOf(newAmount));                
                            
            productsDevol.fireTableDataChanged();
                        
        }
    }//GEN-LAST:event_jTableProductosPedidosDevolMouseClicked

    private void jTableProductosPedidoMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jTableProductosPedidoMouseClicked
    {//GEN-HEADEREND:event_jTableProductosPedidoMouseClicked
        if(evt.getClickCount() == 2)
        {
            //updateProductOrderAmountAndCost();
            //this is handled by the cell changed event of the table.
        }
    }//GEN-LAST:event_jTableProductosPedidoMouseClicked

    private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_openMenuItemActionPerformed
    {//GEN-HEADEREND:event_openMenuItemActionPerformed
        new RawMaterialProductsUI();
    }//GEN-LAST:event_openMenuItemActionPerformed

    private void jButtonRefreshTableActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonRefreshTableActionPerformed
    {//GEN-HEADEREND:event_jButtonRefreshTableActionPerformed
       if (this.jTabbedPane1.getSelectedIndex() == 0) {
            //products
            getAllProductsFromDB();
        }
        else if (this.jTabbedPane1.getSelectedIndex() == 1) {
            //clientes
            getAllClientsFromDB();
        }
        else if (this.jTabbedPane1.getSelectedIndex() == 2) {
            //proveedores
            getAllSuppliersFromDB();
        }
        else if (this.jTabbedPane1.getSelectedIndex() == 3) {
            //mat prima
            getAllMatPrimaFromDB();
        }
        else if (this.jTabbedPane1.getSelectedIndex() == 4) {
            //orders
            getAllOrdersFromDB();
        }
        else if (this.jTabbedPane1.getSelectedIndex() == 5) {
            //returns
            getAllReturnsFromDB();
            
        }
        else if (this.jTabbedPane1.getSelectedIndex() == 6) {
            //sales
            getAllSalesFromDB();
        }

    }//GEN-LAST:event_jButtonRefreshTableActionPerformed

    private void jCheckBoxDeliveredSaleActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jCheckBoxDeliveredSaleActionPerformed
    {//GEN-HEADEREND:event_jCheckBoxDeliveredSaleActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBoxDeliveredSaleActionPerformed

    private void jTableSalesMouseEntered(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jTableSalesMouseEntered
    {//GEN-HEADEREND:event_jTableSalesMouseEntered
        // TODO add your handling code here:
    }//GEN-LAST:event_jTableSalesMouseEntered

    private void jRadioButtonFixedDiscActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jRadioButtonFixedDiscActionPerformed
    {//GEN-HEADEREND:event_jRadioButtonFixedDiscActionPerformed
        if(jRadioButtonFixedDisc.isSelected()){
            jTextFieldDiscountSale.setEditable(true);
        }else{
            jTextFieldDiscountSale.setEditable(false);
        }
    }//GEN-LAST:event_jRadioButtonFixedDiscActionPerformed

    private void jButtonEditOrderRawMaterialActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEditOrderRawMaterialActionPerformed
    {//GEN-HEADEREND:event_jButtonEditOrderRawMaterialActionPerformed
        setOrderRawMaterialFieldsEditable(true);
        jButtonGuardarOrderRawMaterial.setEnabled(true);
        jButtonEditOrderRawMaterial.setEnabled(false);
    }//GEN-LAST:event_jButtonEditOrderRawMaterialActionPerformed

    private void jButtonGuardarOrderRawMaterialActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonGuardarOrderRawMaterialActionPerformed
    {//GEN-HEADEREND:event_jButtonGuardarOrderRawMaterialActionPerformed
        try {
            createOrSaveOrderRawMaterial();
            setOrderRawMaterialFieldsEditable(false);
            this.jButtonEditOrderRawMaterial.setEnabled(true);
            this.jButtonEliminarOrderRawMaterial.setEnabled(true);
            jTableOrdersRawMaterial.setModel(getOrdersRawMaterialListModel());
            this.jOrdersRawMaterialPanel.setVisible(false);
        }
        catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }

    }//GEN-LAST:event_jButtonGuardarOrderRawMaterialActionPerformed

    private void jButtonCancelarOrderRawMaterialActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonCancelarOrderRawMaterialActionPerformed
    {//GEN-HEADEREND:event_jButtonCancelarOrderRawMaterialActionPerformed
        this.jOrdersRawMaterialPanel.setVisible(false);
    }//GEN-LAST:event_jButtonCancelarOrderRawMaterialActionPerformed

    private void jButtonEliminarOrderRawMaterialActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonEliminarOrderRawMaterialActionPerformed
    {//GEN-HEADEREND:event_jButtonEliminarOrderRawMaterialActionPerformed
        try {
            deleteOrderRawMaterial();
            dataOrderRawMaterialFormClean();
            setOrderRawMaterialFieldsEditable(true);
            this.jButtonEditOrderRawMaterial.setEnabled(false);
            this.jButtonEliminarOrderRawMaterial.setEnabled(false);
            this.jButtonGuardarOrderRawMaterial.setEnabled(true);
            jTableOrdersRawMaterial.setModel(getOrdersListModel());
            jOrdersRawMaterialPanel.setVisible(false);
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }
    }//GEN-LAST:event_jButtonEliminarOrderRawMaterialActionPerformed

    private void jComboBoxProveedorRawMaterialActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jComboBoxProveedorRawMaterialActionPerformed
    {//GEN-HEADEREND:event_jComboBoxProveedorRawMaterialActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxProveedorRawMaterialActionPerformed

    private void jTextFieldBuscarRawMaterialActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextFieldBuscarRawMaterialActionPerformed
    {//GEN-HEADEREND:event_jTextFieldBuscarRawMaterialActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldBuscarRawMaterialActionPerformed

    private void jButtonBuscarRawMaterialActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonBuscarRawMaterialActionPerformed
    {//GEN-HEADEREND:event_jButtonBuscarRawMaterialActionPerformed
        //find raw mat
        findRawMaterials();
    }//GEN-LAST:event_jButtonBuscarRawMaterialActionPerformed

    private void jButtonBuscarRawMaterialKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jButtonBuscarRawMaterialKeyPressed
    {//GEN-HEADEREND:event_jButtonBuscarRawMaterialKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonBuscarRawMaterialKeyPressed

    private void jListRawMaterialMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jListRawMaterialMouseClicked
    {//GEN-HEADEREND:event_jListRawMaterialMouseClicked
        if(evt.getClickCount() == 2){
            RawMaterial selected = (RawMaterial) jListRawMaterial.getSelectedValue();
            double totalCost;
            if(jTextFieldTotalOrderRawMaterial.getText().isEmpty()){
                totalCost = 0;
            }else{
                totalCost = Double.valueOf(jTextFieldTotalOrderRawMaterial.getText());
            }
            totalCost+=selected.getPrice();
                
            DefaultTableModel rawMaterialsOrder = (DefaultTableModel) jTableRawMaterialPedido.getModel();
            boolean newMat = true;
            for (Iterator it = rawMaterialsOrder.getDataVector().iterator(); it.hasNext();) {
                Vector object = (Vector) it.next();
                RawMaterial rawMat = (RawMaterial) object.get(0);
                if(rawMat.equals(selected)){
                    String value = (String) object.get(1);
                    int newCant = Integer.valueOf(value) + 1;
                    object.set(1, String.valueOf(newCant));
                    
                    double cost = Double.valueOf((String)object.get(2));
                    double newCost = rawMat.getPrice()+cost;
                    object.set(2, String.valueOf(newCost));
                    newMat = false;
                }                
            }
            if(newMat){
                rawMaterialsOrder.addRow(new Object[]{selected,"1",String.valueOf(selected.getPrice())});
            }
            rawMaterialsOrder.fireTableDataChanged();
            jTableRawMaterialPedido.setModel(rawMaterialsOrder);
            jTextFieldTotalOrderRawMaterial.setText(String.valueOf(Math.rint(totalCost)));
        }
    }//GEN-LAST:event_jListRawMaterialMouseClicked

    private void jTableRawMaterialPedidoMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jTableRawMaterialPedidoMouseClicked
    {//GEN-HEADEREND:event_jTableRawMaterialPedidoMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jTableRawMaterialPedidoMouseClicked

    private void jTableOrdersRawMaterialMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jTableOrdersRawMaterialMouseClicked
    {//GEN-HEADEREND:event_jTableOrdersRawMaterialMouseClicked
        if (evt.getClickCount() == 2)
        {
            selectOrderRawMaterial();
        }
    }//GEN-LAST:event_jTableOrdersRawMaterialMouseClicked

    private void jTableOrdersRawMaterialPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_jTableOrdersRawMaterialPropertyChange
    {//GEN-HEADEREND:event_jTableOrdersRawMaterialPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jTableOrdersRawMaterialPropertyChange

    private void jTableOrdersRawMaterialKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTableOrdersRawMaterialKeyPressed
    {//GEN-HEADEREND:event_jTableOrdersRawMaterialKeyPressed
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){
            selectOrderRawMaterial();
            
        }
    }//GEN-LAST:event_jTableOrdersRawMaterialKeyPressed

    private void contentsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contentsMenuItemActionPerformed
        ReportsUI.main(null);
    }//GEN-LAST:event_contentsMenuItemActionPerformed

    private void jTextFieldMatPrimaPrecioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldMatPrimaPrecioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldMatPrimaPrecioActionPerformed

    private void jButtonGuardarPreciosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarPreciosActionPerformed
        try {
                    
            DefaultTableModel products = (DefaultTableModel) jTableProductosNuevoPrecio.getModel();
            for (Iterator it = products.getDataVector().iterator(); it.hasNext();) {
                Vector object = (Vector) it.next();
                String prodCode = (String) object.get(0);
                double newPrice = (double) object.get(3);

                //Find product
                Product product = productManager.find(prodCode);
                if (product != null) {

                    product.getProductPrice().add(new Price(newPrice, new Date()));
                    productManager.saveProduct(product);
                }
            }

            JOptionPane.showMessageDialog(null, "Todos los productos fueron actualizados correctamente");
            dataPricePanelFormClean();

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Ocurrio un error actualizando los productos");
            System.out.println("Error: " + e.getMessage());
        }
    }//GEN-LAST:event_jButtonGuardarPreciosActionPerformed

    private void jButtonCancelarPreciosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarPreciosActionPerformed
        this.jPricePanel.setVisible(false);
    }//GEN-LAST:event_jButtonCancelarPreciosActionPerformed

    private void jTextFieldBuscarProdActualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldBuscarProdActualizarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldBuscarProdActualizarActionPerformed

    private void jButtonBuscarProductosActPrecioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuscarProductosActPrecioActionPerformed
        findProductsPrice();
    }//GEN-LAST:event_jButtonBuscarProductosActPrecioActionPerformed

    private void jButtonBuscarProductosActPrecioKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButtonBuscarProductosActPrecioKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonBuscarProductosActPrecioKeyPressed

    private void jListProductosActualizarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jListProductosActualizarMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jListProductosActualizarMouseClicked

    private void jTableProductosNuevoPrecioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableProductosNuevoPrecioMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jTableProductosNuevoPrecioMouseClicked

    private void jIncreasePriceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jIncreasePriceButtonActionPerformed
        
        updateProductPrices("+");
        
    }//GEN-LAST:event_jIncreasePriceButtonActionPerformed

    private void jDecreasePriceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jDecreasePriceButtonActionPerformed
        
        updateProductPrices("-");
    }//GEN-LAST:event_jDecreasePriceButtonActionPerformed

    private void jButtonUpdateProductsPriceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonUpdateProductsPriceActionPerformed
        
        dataPricePanelFormClean();

        this.jTextFieldBuscarProdActualizar.setEnabled(true);
        this.jTextFieldBuscarProdActualizar.setEditable(true);
        this.jButtonCancelarPrecios.setEnabled(true);
        this.jButtonGuardarPrecios.setEnabled(true);
        this.jPricePanel.setVisible(true);
    }//GEN-LAST:event_jButtonUpdateProductsPriceActionPerformed

    private void jOkNewPriceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jOkNewPriceButtonActionPerformed
        if(!jFixedNewPriceTextField.getText().isEmpty() 
                && jListProductosActualizar.getModel().getSize() > 0)
        {
            jPorcentajePrecioTextField.setText("");
            double price = Double.valueOf(jFixedNewPriceTextField.getText());
            setProductsPriceTable(price, "FIXED");
            
        }
    }//GEN-LAST:event_jOkNewPriceButtonActionPerformed

    private void jPricePanelFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jPricePanelFocusLost
        this.jPricePanel.setVisible(false);
    }//GEN-LAST:event_jPricePanelFocusLost

    private void formWindowLostFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowLostFocus
        
    }//GEN-LAST:event_formWindowLostFocus

    private DefaultTableModel getProductsOrderListModel()
    {
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                if(col==1 || col==2){
                    return true;
                }
                return false;
            }
        };
        
        String col[] = {"Producto","Cantidad","Costo"};
        dm.setColumnIdentifiers(col);
        
        dm.addTableModelListener(new TableModelListener()
        {
            public void tableChanged(TableModelEvent e)
            {
                if(e.getColumn()==1){
                    updateProductOrderAmount(Constants.ADD_OPERATION);    
                }else if(e.getColumn()==2){
                    updateProductOrderCost();    
                }
                
            }
        });
        
        return dm;
    }
    
    private DefaultTableModel getProductsSaleListModel()
    {
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                if(col == 1 || col == 3){
                    return true;
                }
                return false;                
            }
        };
        
        String col[] = {"Producto","Cantidad","Stock Disp.","Precio"};
        dm.setColumnIdentifiers(col);
        
        dm.addTableModelListener(new TableModelListener()
        {
            public void tableChanged(TableModelEvent e)
            {
                if(e.getColumn()==1){
                    updateProductSaleAmount(Constants.ADD_OPERATION);    
                }else if(e.getColumn()==3){
                    updateProductSaleSubtotal();    
                }
                
            }
        });
        
        return dm;
    }
        
    private DefaultTableModel getRawMaterialOrderListModel()
    {
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                if(col == 1 || col == 3){
                    return true;
                }
                return false;                
            }
        };
        
        String col[] = {"Producto","Cantidad","Precio"};
        dm.setColumnIdentifiers(col);
        
        dm.addTableModelListener(new TableModelListener()
        {
            public void tableChanged(TableModelEvent e)
            {
                if(e.getColumn()==1){
                    updateProductSaleAmount(Constants.ADD_OPERATION);    
                }else if(e.getColumn()==3){
                    updateProductSaleSubtotal();    
                }
                
            }
        });
        
        return dm;
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        }
        catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DieciUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DieciUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DieciUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DieciUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                new DieciUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel Center;
    private javax.swing.JPanel East;
    private javax.swing.JPanel North;
    private javax.swing.JPanel South;
    private javax.swing.JPanel West;
    private javax.swing.ButtonGroup buttonGroupDiscount;
    private javax.swing.ButtonGroup buttonGroupOrdersSearch;
    private javax.swing.JMenuItem contentsMenuItem;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonBuscarPedidos;
    private javax.swing.JButton jButtonBuscarProductos;
    private javax.swing.JButton jButtonBuscarProductosActPrecio;
    private javax.swing.JButton jButtonBuscarProductosSale;
    private javax.swing.JButton jButtonBuscarRawMaterial;
    private javax.swing.JButton jButtonCalTotalSale;
    private javax.swing.JButton jButtonCancelarCliente;
    private javax.swing.JButton jButtonCancelarMatPrima;
    private javax.swing.JButton jButtonCancelarOrder;
    private javax.swing.JButton jButtonCancelarOrderRawMaterial;
    private javax.swing.JButton jButtonCancelarPrecios;
    private javax.swing.JButton jButtonCancelarProducto;
    private javax.swing.JButton jButtonCancelarProveedor;
    private javax.swing.JButton jButtonCancelarReturn;
    private javax.swing.JButton jButtonCancelarSale;
    private javax.swing.JButton jButtonEditOrder;
    private javax.swing.JButton jButtonEditOrderRawMaterial;
    private javax.swing.JButton jButtonEditProduct;
    private javax.swing.JButton jButtonEditReturn;
    private javax.swing.JButton jButtonEditSale;
    private javax.swing.JButton jButtonEditarCliente;
    private javax.swing.JButton jButtonEditarMatPrima;
    private javax.swing.JButton jButtonEditarProveedor;
    private javax.swing.JButton jButtonEliminarCliente;
    private javax.swing.JButton jButtonEliminarMatPrima;
    private javax.swing.JButton jButtonEliminarOrder;
    private javax.swing.JButton jButtonEliminarOrderRawMaterial;
    private javax.swing.JButton jButtonEliminarProducto;
    private javax.swing.JButton jButtonEliminarProveedor;
    private javax.swing.JButton jButtonEliminarReturn;
    private javax.swing.JButton jButtonEliminarSale;
    private javax.swing.JButton jButtonGuardarCliente;
    private javax.swing.JButton jButtonGuardarMatPrima;
    private javax.swing.JButton jButtonGuardarOrder;
    private javax.swing.JButton jButtonGuardarOrderRawMaterial;
    private javax.swing.JButton jButtonGuardarPrecios;
    private javax.swing.JButton jButtonGuardarProducto;
    private javax.swing.JButton jButtonGuardarProveedor;
    private javax.swing.JButton jButtonGuardarReturn;
    private javax.swing.JButton jButtonGuardarSale;
    private javax.swing.JButton jButtonRefreshTable;
    private javax.swing.JButton jButtonUpdateProductsPrice;
    private javax.swing.JCheckBox jCheckBoxChargedSale;
    private javax.swing.JCheckBox jCheckBoxDeliveredSale;
    private javax.swing.JPanel jClientesPanel;
    private javax.swing.JComboBox jComboBoxClient;
    private javax.swing.JComboBox jComboBoxProveedor;
    private javax.swing.JComboBox jComboBoxProveedorRawMaterial;
    private javax.swing.JComboBox jComboBoxTalle;
    private javax.swing.JComboBox jComboBoxUniMedida;
    private javax.swing.JButton jDecreasePriceButton;
    private javax.swing.JTextField jFixedNewPriceTextField;
    private javax.swing.JLabel jImagenFondo;
    private javax.swing.JButton jIncreasePriceButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    private javax.swing.JLabel jLabel42;
    private javax.swing.JLabel jLabel43;
    private javax.swing.JLabel jLabel44;
    private javax.swing.JLabel jLabel45;
    private javax.swing.JLabel jLabel46;
    private javax.swing.JLabel jLabel47;
    private javax.swing.JLabel jLabel48;
    private javax.swing.JLabel jLabel49;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel50;
    private javax.swing.JLabel jLabel51;
    private javax.swing.JLabel jLabel52;
    private javax.swing.JLabel jLabel53;
    private javax.swing.JLabel jLabel54;
    private javax.swing.JLabel jLabel55;
    private javax.swing.JLabel jLabel56;
    private javax.swing.JLabel jLabel57;
    private javax.swing.JLabel jLabel58;
    private javax.swing.JLabel jLabel59;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel61;
    private javax.swing.JLabel jLabel62;
    private javax.swing.JLabel jLabel63;
    private javax.swing.JLabel jLabel65;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelDateSince;
    private javax.swing.JLabel jLabelDateTo;
    private javax.swing.JLabel jLabelStockAvailable;
    private javax.swing.JLabel jLabelStockOnReturn;
    private javax.swing.JLabel jLabelStockTotal;
    private javax.swing.JLabel jLabelSupplier;
    private javax.swing.JList jListPedidos;
    private javax.swing.JList jListProductos;
    private javax.swing.JList jListProductosActualizar;
    private javax.swing.JList jListProductosSale;
    private javax.swing.JList jListRawMaterial;
    private javax.swing.JPanel jMatPrimaPanel;
    private javax.swing.JButton jOkNewPriceButton;
    private javax.swing.JTextField jOrderRawMaterialIDTextField;
    private javax.swing.JPanel jOrdersPanel;
    private javax.swing.JPanel jOrdersRawMaterialPanel;
    private javax.swing.JPanel jPanelClients;
    private javax.swing.JPanel jPanelMateriaPrima;
    private javax.swing.JPanel jPanelOrders;
    private javax.swing.JPanel jPanelOrdersRawMaterial;
    private javax.swing.JPanel jPanelProducts;
    private javax.swing.JPanel jPanelReturns;
    private javax.swing.JPanel jPanelSales;
    private javax.swing.JPanel jPanelSupplier;
    private javax.swing.JTextField jPorcentajePrecioTextField;
    private javax.swing.JPanel jPricePanel;
    private javax.swing.JPanel jProductsPanel;
    private javax.swing.JRadioButton jRadioButtonDateSearch;
    private javax.swing.JRadioButton jRadioButtonFixedDisc;
    private javax.swing.JRadioButton jRadioButtonPercentDisc;
    private javax.swing.JRadioButton jRadioButtonSupplierSearch;
    private javax.swing.JPanel jReturnsPanel;
    private javax.swing.JPanel jSalesPanel;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JScrollPane jScrollPaneClients;
    private javax.swing.JScrollPane jScrollPaneMatPrima;
    private javax.swing.JScrollPane jScrollPaneOrders;
    private javax.swing.JScrollPane jScrollPaneOrdersRawMaterial;
    private javax.swing.JScrollPane jScrollPaneProducts;
    private javax.swing.JScrollPane jScrollPaneReturns;
    private javax.swing.JScrollPane jScrollPaneSales;
    private javax.swing.JScrollPane jScrollPaneSuppliers;
    private javax.swing.JPanel jSuppliersPanel;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTableClients;
    private javax.swing.JTable jTableMatPrima;
    private javax.swing.JTable jTableOrders;
    private javax.swing.JTable jTableOrdersRawMaterial;
    private javax.swing.JTable jTableProductosNuevoPrecio;
    private javax.swing.JTable jTableProductosPedido;
    private javax.swing.JTable jTableProductosPedidosDevol;
    private javax.swing.JTable jTableProductosSale;
    private javax.swing.JTable jTableProducts;
    private javax.swing.JTable jTableRawMaterialPedido;
    private javax.swing.JTable jTableReturns;
    private javax.swing.JTable jTableSales;
    private javax.swing.JTable jTableSuppliers;
    private javax.swing.JTextArea jTextAreaDesc;
    private javax.swing.JTextField jTextFieldArticulo;
    private javax.swing.JTextField jTextFieldBuscarProd;
    private javax.swing.JTextField jTextFieldBuscarProdActualizar;
    private javax.swing.JTextField jTextFieldBuscarProdSale;
    private javax.swing.JTextField jTextFieldBuscarRawMaterial;
    private javax.swing.JTextField jTextFieldClienteContacto;
    private javax.swing.JTextField jTextFieldClienteDir;
    private javax.swing.JTextField jTextFieldClienteWeb;
    private javax.swing.JTextField jTextFieldColor;
    private javax.swing.JFormattedTextField jTextFieldDateSince;
    private javax.swing.JFormattedTextField jTextFieldDateTo;
    private javax.swing.JTextField jTextFieldDiscountSale;
    private javax.swing.JTextField jTextFieldEmailCliente;
    private javax.swing.JTextField jTextFieldMatPrimaCant;
    private javax.swing.JTextField jTextFieldMatPrimaNom;
    private javax.swing.JTextField jTextFieldMatPrimaPrecio;
    private javax.swing.JTextField jTextFieldNomCliente;
    private javax.swing.JTextField jTextFieldNomSupplier;
    private javax.swing.JTextField jTextFieldNombre;
    private javax.swing.JFormattedTextField jTextFieldOrderDate;
    private javax.swing.JFormattedTextField jTextFieldOrderRawMaterialDate;
    private javax.swing.JTextField jTextFieldPrecio;
    private javax.swing.JTextField jTextFieldProvContacto;
    private javax.swing.JTextField jTextFieldProvDir;
    private javax.swing.JTextField jTextFieldProvEmail;
    private javax.swing.JTextField jTextFieldProvTel;
    private javax.swing.JTextField jTextFieldProvWeb;
    private javax.swing.JFormattedTextField jTextFieldReturnDate;
    private javax.swing.JFormattedTextField jTextFieldSaleDate;
    private javax.swing.JTextField jTextFieldSaleSubTotal;
    private javax.swing.JTextField jTextFieldSupplier;
    private javax.swing.JTextField jTextFieldTelCliente;
    private javax.swing.JTextField jTextFieldTotalOrder;
    private javax.swing.JTextField jTextFieldTotalOrderRawMaterial;
    private javax.swing.JTextField jTextFieldTotalSale;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem openMenuItem;
    // End of variables declaration//GEN-END:variables

    private void setAllPanelsInvisible()
    {
        this.jProductsPanel.setVisible(false);
        this.jSuppliersPanel.setVisible(false);
        this.jClientesPanel.setVisible(false);
        this.jMatPrimaPanel.setVisible(false);
        this.jOrdersPanel.setVisible(false);
        this.jReturnsPanel.setVisible(false);
        this.jSalesPanel.setVisible(false);
        this.jOrdersRawMaterialPanel.setVisible(false);
        this.jPricePanel.setVisible(false);
    }

    private void setProductFieldsEditable(boolean editable)
    {
        this.jTextFieldArticulo.setEditable(editable);
        this.jTextAreaDesc.setEditable(editable);
        this.jTextFieldColor.setEditable(editable);
        this.jTextFieldNombre.setEditable(editable);
        this.jTextFieldPrecio.setEditable(editable);
        this.jComboBoxTalle.setEnabled(editable);
    }
    
    private void setMatPrimaFieldsEditable(boolean editable)
    {
        this.jTextFieldMatPrimaNom.setEditable(editable);
        this.jTextFieldMatPrimaCant.setEditable(editable);
        this.jTextFieldMatPrimaPrecio.setEditable(editable);
        this.jComboBoxUniMedida.setEnabled(editable);
    }

    private void createOrSaveProduct() throws Exception
    {
        //CREATE OR SAVE PRODUCT
        Product product = null;

        try {
            product = getProductData();
            if (product != null) {
                if (product.getProductDescription().isEmpty()
                        || product.getProductCode().isEmpty()) {
                    throw new Exception("Debe ingresar el articulo y descripcion del producto ");
                }
                else 
                {
                    productManager.saveProduct(product);
                }
            }
        }
        catch (Exception e2) {
            throw e2;
        }
    }

    private void createOrSaveMatPrima()
    {
        //CREATE OR SAVE
        RawMaterial rawMaterial = null;

        try {
            rawMaterial = getRawMaterialData();
            if (rawMaterial != null) {
                if (rawMaterial.getName().isEmpty()
                        || rawMaterial.getAmount() <= 0 || rawMaterial.getPrice() <= 0) {
                    JOptionPane.showMessageDialog(null, "Debe ingresar todos los datos");
                }
                else 
                {
                    rawMaterialManager.saveRawMaterial(rawMaterial);
                }
            }
        }
        catch (Exception e2) {
            JOptionPane.showMessageDialog(null, e2.getMessage());
        }
    }
    
    private void createOrSaveOrder() throws Exception
    {
        //CREATE OR SAVE
        Order order = null;

        try {
            order = getOrderData();
            Map<Long, Integer> productsAmountToOrder;
            if (order != null) {

                if (order.getSupplier() == null
                        || order.getDetails().isEmpty()) {
                    throw new Exception("Debe ingresar el proveedor y los detalles de la compra ");
                }
                else {

                    Order originalOrder = orderManager.find(order.getOrderId());
                    productsAmountToOrder = getAlreadyOrderedAmountForOrderProducts(originalOrder);

                    Vector productOrderDetails = getProductOrderDetails();
                    for (Iterator it = productOrderDetails.iterator(); it.hasNext();) {
                        Vector object = (Vector) it.next();
                        Product product = (Product) object.get(0);
                        int amountToOrder = Integer.valueOf((String) object.get(1));
                        long prodId = product.getProductId();
                        int updatedAmount = amountToOrder;
                        if (productsAmountToOrder.containsKey(prodId)) {
                            int existingAmount = productsAmountToOrder.get(prodId);

                            updatedAmount = amountToOrder - existingAmount;

                        }

                        productsAmountToOrder.put(prodId, updatedAmount);

                    }

                    orderManager.saveOrder(order);


                    updateProductStockForNewOrder(productsAmountToOrder, Constants.ADD_OPERATION);

                }
            }

        }
        catch (Exception e2) {
            throw e2;
        }
    }
    
    private void createOrSaveOrderRawMaterial() throws Exception
    {
        //CREATE OR SAVE
        OrderRawMaterial orderRawMaterial = null;
        OrderRawMaterial orderRawMaterialOriginal = null;

        try {
            orderRawMaterial = getOrderRawMaterialData();
            
            if (orderRawMaterial != null) {

                if (orderRawMaterial.getSupplier() == null
                        || orderRawMaterial.getDetails().isEmpty()) {
                    throw new Exception("Debe ingresar el proveedor y los detalles de la compra ");
                }
                else {
                    String orderId = jOrderRawMaterialIDTextField.getText();
                    if(orderId != null && !orderId.isEmpty())
                    {
                        orderRawMaterialOriginal = orderRawMaterialManager.find(Long.valueOf(orderId));
                        updateRawMaterialStock(orderRawMaterial,orderRawMaterialOriginal);
                    }
                    else
                    {
                        updateRawMaterialStock(orderRawMaterial,null);
                    }
                    orderRawMaterialManager.saveOrderRawMaterial(orderRawMaterial);
                    
                }
            }

        }
        catch (Exception e2) {
            throw e2;
        }
    }
    
    private void createOrUpdateReturn() throws Exception
    {
        //CREATE OR SAVE
        Return returnOrder = null;
        Map<Long, Integer> productsAmountToReturn;
        try {
            returnOrder = getReturnData();
            if (returnOrder != null) {
                
                Return originalReturnOrder = returnManager.find(returnOrder.getReturnId());
                productsAmountToReturn = getAlreadyReturnedAmountForOrderProducts(originalReturnOrder);
                
                Vector productReturnDetails = getProductReturnDetails();
                int quantityGraterThanZeroForAtLeastOneProduct = productReturnDetails.size();
                boolean quantityGraterThanOrderedAmount = false;
                for (Iterator it = productReturnDetails.iterator(); it.hasNext();) {
                    Vector object = (Vector)it.next();
                    Product product = (Product)object.get(0);
                    int amountToReturn = Integer.valueOf((String)object.get(2));
                    int amountBought = Integer.valueOf((String)object.get(1));
                    if(amountToReturn >= 0){
                        if(amountToReturn==0) quantityGraterThanZeroForAtLeastOneProduct--;
                        if(amountToReturn > amountBought){
                            quantityGraterThanOrderedAmount = true;
                        }else{
                            long prodId = product.getProductId();
                            int updatedAmount = amountToReturn;
                            if(productsAmountToReturn.containsKey(prodId)){
                                int existingAmount = productsAmountToReturn.get(prodId);
                               updatedAmount =  amountToReturn - existingAmount;
                                    
                            }
                            productsAmountToReturn.put(prodId, updatedAmount);
                            
                        }
                    }
                }
                if (quantityGraterThanZeroForAtLeastOneProduct == 0 || quantityGraterThanOrderedAmount) {
                    if(quantityGraterThanOrderedAmount){
                        throw new Exception("La cantidad a devolver debe ser menor o igual a la comprada");
                    }else{
                        if(returnOrder.getReturnId() == 0){
                            //Do noy allow the amount zero when a new return is done. For updates zero it's allowed.   
                            throw new Exception("Debe ingresar la cantidad a devolver de al menos un producto ");
                        }
                        
                    }
                }
                
                returnManager.saveReturn(returnOrder);
                
                
                updateProductStockForReturn(productsAmountToReturn,Constants.ADD_OPERATION);
                
                    
            }
        }
        catch (Exception e2) {
            throw e2;
        }
    }    
    
        
    private Product getProductData()
    {
        //get product data from form
        Product prod = null;
        String article, name, longDescription, prodSize, color;
        double price = 0 , costPrice=0;

        article = jTextFieldArticulo.getText();
        name = jTextFieldNombre.getText();
        longDescription = jTextAreaDesc.getText();
        if(!jTextFieldPrecio.getText().isEmpty())
        {
            price = Double.parseDouble(jTextFieldPrecio.getText());
        }
        
        prodSize = jComboBoxTalle.getSelectedItem().toString();
        color = jTextFieldColor.getText();

        prod = new Product(article, name, longDescription, new Price(price, new Date()), 
                prodSize, color,costPrice,0);

        return prod;
    }

    private Order getOrderData()
    {
        //get data from form
        Order ord = null;
        SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        Date orderDate;
        if (jTextFieldOrderDate.getText().isEmpty()) {
            orderDate = new Date();
        }
        else
        {
            try {    
                orderDate = df.parse(jTextFieldOrderDate.getText());
            }
            catch (ParseException ex) {
                orderDate = new Date();
            }
        }         
        
        
        Set<OrderDetails> details = new HashSet<>();
        Supplier sup;
        
        sup = (Supplier) jComboBoxProveedor.getSelectedItem();
        DefaultTableModel orderDetails = (DefaultTableModel) jTableProductosPedido.getModel();
        for (Iterator it = orderDetails.getDataVector().iterator(); it.hasNext();) {
            Vector object = (Vector)it.next();
            Product product = (Product) object.get(0);
            int amount = Integer.valueOf((String)object.get(1));
            double cost = Double.valueOf((String)object.get(2));
            OrderDetails detail = new OrderDetails(product.getProductId(),amount,cost);
            details.add(detail);
        }
        
        double totalOrder = Double.valueOf(jTextFieldTotalOrder.getText());
        
        int selectedRowIndex = jTableOrders.getSelectedRow();
        long selected = 0;
        if(selectedRowIndex >= 0){
            int selectedColumnIndex = 0;
            selected = (long) jTableOrders.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);
            ord = new Order(selected, sup, orderDate, details, totalOrder);
        }else{
            ord = new Order(sup, orderDate, details, totalOrder);    
        }
        
        return ord;
    }
    
    private OrderRawMaterial getOrderRawMaterialData()
    {
        //get data from form
        OrderRawMaterial ord = null;
        SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        Date orderDate;
        if (jTextFieldOrderRawMaterialDate.getText().isEmpty()) {
            orderDate = new Date();
        }
        else
        {
            try {    
                orderDate = df.parse(jTextFieldOrderRawMaterialDate.getText());
            }
            catch (ParseException ex) {
                orderDate = new Date();
            }
        }         
        
        
        Set<OrderRawMaterialDetails> details = new HashSet<>();
        Supplier sup;
        
        sup = (Supplier) jComboBoxProveedorRawMaterial.getSelectedItem();
        DefaultTableModel orderDetails = (DefaultTableModel) jTableRawMaterialPedido.getModel();
        for (Iterator it = orderDetails.getDataVector().iterator(); it.hasNext();) {
            Vector object = (Vector)it.next();
            RawMaterial rawMaterial = (RawMaterial) object.get(0);
            int amount = Integer.valueOf((String)object.get(1));
            double cost = Double.valueOf((String)object.get(2));
            OrderRawMaterialDetails detail = new OrderRawMaterialDetails(rawMaterial.getRawMaterialId(),amount,cost);
            details.add(detail);
        }
        
        double totalOrder = Double.valueOf(jTextFieldTotalOrderRawMaterial.getText());
        
        int selectedRowIndex = jTableOrdersRawMaterial.getSelectedRow();
        long selected = 0;
        if(selectedRowIndex >= 0){
            int selectedColumnIndex = 0;
            selected = (long) jTableOrdersRawMaterial.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);
            ord = new OrderRawMaterial(selected, sup, orderDate, details, totalOrder);
        }else{
            ord = new OrderRawMaterial(sup, orderDate, details, totalOrder);    
        }
        
        return ord;
    }
    
    private Return getReturnData()
    {
        //get data from form
        Return ret = null;
        SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        Date returnDate;
        String stringDate = jTextFieldReturnDate.getText();
        if (stringDate.isEmpty()) {
            returnDate = new Date();
        }
        else
        {
            try {    
                returnDate = df.parse(stringDate);
            }
            catch (ParseException ex) {
                returnDate = new Date();
            }
        }         
        
        
        Set<ReturnDetails> details = new HashSet<>();
        Supplier sup;
        Order order = (Order)jListPedidos.getSelectedValue();
        sup = order.getSupplier();
        DefaultTableModel returnDetails = (DefaultTableModel) jTableProductosPedidosDevol.getModel();
        for (Iterator it = returnDetails.getDataVector().iterator(); it.hasNext();) {
            Vector object = (Vector)it.next();
            Product product = (Product) object.get(0);
            int amount = Integer.valueOf((String)object.get(2));
            ReturnDetails retDetail = new ReturnDetails(product.getProductId(), amount);
            details.add(retDetail);
        }
        
        //this is needed in the case an update is done to the return
        int selectedRowIndex = jTableReturns.getSelectedRow();
        int selectedColumnIndex = 0;
        Long selected = null;
        if(selectedRowIndex >= 0)
        {
            selected = (Long) jTableReturns.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);
        }         
        
        ret = new Return(sup, order, returnDate, details);
        
        if(selected!=null)
        {
            ret.setReturnId(selected);
        }
        
        return ret;
    }
    
    private Sale getSaleData()
    {
        //get data from form
        Sale sale = null;
        SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        Date saleDate;
        if (jTextFieldSaleDate.getText().isEmpty()) {
            saleDate = new Date();
        }
        else
        {
            try {    
                saleDate = df.parse(jTextFieldSaleDate.getText());
            }
            catch (ParseException ex) {
                saleDate = new Date();
            }
        }         
        
        
        Set<SaleDetails> details = new HashSet<>();
        Client client;
        
        client = (Client) jComboBoxClient.getSelectedItem();
        DefaultTableModel saleDetails = (DefaultTableModel) jTableProductosSale.getModel();
        for (Iterator it = saleDetails.getDataVector().iterator(); it.hasNext();) {
            Vector object = (Vector)it.next();
            Product product = (Product) object.get(0);
            int amount = Integer.valueOf((String)object.get(1));
            double price = Double.valueOf((String)object.get(3));
            SaleDetails detail = new SaleDetails(product,amount,price);
            details.add(detail);
        }
        
        
        double disc = 0;
        if(!jTextFieldDiscountSale.getText().isEmpty()){
            disc = Double.valueOf(jTextFieldDiscountSale.getText());
        }
        double total = getTotalForSale();
        
        boolean charged = jCheckBoxChargedSale.isSelected();
        boolean delivered = jCheckBoxDeliveredSale.isSelected();
        
        String discType = "";
        if(jRadioButtonFixedDisc.isSelected()){
            discType = Constants.FIXED_DISCOUNT;
        }else if(jRadioButtonPercentDisc.isSelected()){
            discType = Constants.PERCENTAGE_DISCOUNT;
        }
    
        int selectedRowIndex = jTableSales.getSelectedRow();
        long selected = 0;
        if(selectedRowIndex >= 0)
        {
            int selectedColumnIndex = 0;
            selected = (long) jTableSales.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);    
        }
        
        if(selected > 0)
        {
            sale = new Sale(selected, client, saleDate, details, disc, discType, total, charged, delivered);
        }        
        else
        {
            sale = new Sale(client, saleDate, details, disc, discType, total, charged, delivered);    
        }
                
        return sale;
    }
    
    private RawMaterial getRawMaterialData()
    {
        //get data from form
        RawMaterial material = null;
        String name, messureUnit; 
        float amount;
        double price;

        name = jTextFieldMatPrimaNom.getText();
        amount = Float.parseFloat(jTextFieldMatPrimaCant.getText());
        price = Double.parseDouble(jTextFieldMatPrimaPrecio.getText());
        messureUnit = jComboBoxUniMedida.getSelectedItem().toString();
        
        //get the id if it's un update
        int id = getSelectedMatPrimaId();
        if(id > 0){
            material = new RawMaterial(id,name, messureUnit, amount, price,0);
        }else{
            material = new RawMaterial(name, messureUnit, amount, price,0);
        }
        

        return material;
    }
    
    private void createOrSaveClient() throws Exception
    {
        //CREATE OR SAVE
        Client client = null;

        try {
            client = getClientData();
            if (client != null) {
                if (client.getName().isEmpty()) {
                    throw new Exception("Debe ingresar el nombre del cliente ");
                }
                else 
                {
                    clientManager.saveClient(client);
                }
            }
        }
        catch (Exception e2) {
            throw e2;
        }
    }
    
    private void createOrSaveSupplier()
    {
        //CREATE OR SAVE
        Supplier supplier;

        try {
            supplier = getSupplierData();
            if (supplier != null) {
                if (supplier.getName().isEmpty()) {
                    JOptionPane.showMessageDialog(null, "Debe ingresar el nombre del proveedor ");
                }
                else 
                {
                    supplierManager.saveSupplier(supplier);
                }
            }
        }
        catch (Exception e2) {
            JOptionPane.showMessageDialog(null, e2.getMessage());
        }
    }
    
    private Client getClientData()
    {
        //get data from form
        Client cli;
        String name, email, phone, contactPerson, adress, webSite;

        name = jTextFieldNomCliente.getText();
        email = jTextFieldEmailCliente.getText();
        phone = jTextFieldTelCliente.getText();
        contactPerson = jTextFieldClienteContacto.getText();
        adress = jTextFieldClienteDir.getText();
        webSite = jTextFieldClienteWeb.getText();
        
        cli = new Client(name, phone, email, adress, contactPerson, webSite,0);

        return cli;
    }
    
    private Supplier getSupplierData()
    {
        //get data from form
        Supplier sup;
        String name, contact, address, email, phone, web;

        name = jTextFieldNomSupplier.getText();
        contact = jTextFieldProvContacto.getText();
        address = jTextFieldProvDir.getText();
        email = jTextFieldProvEmail.getText();
        phone = jTextFieldProvTel.getText();
        web = jTextFieldProvWeb.getText();

        int selectedRowIndex = jTableSuppliers.getSelectedRow();
        int suppId = 0;
        if (selectedRowIndex >= 0) {
            int selectedColumnIndex = 0;
            suppId = (int) jTableSuppliers.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);

        }
        if(suppId > 0){
            sup = new Supplier(suppId, name, contact, address, email, phone, web,0);
        }else{
            sup = new Supplier(name, contact, address, email, phone, web,0);
        }        
        

        return sup;
    }
    
    public void dataProductFormClean()
    {
        jTextFieldArticulo.setText("");
        jTextAreaDesc.setText("");
        jTextFieldColor.setText("");
        jTextFieldNombre.setText("");
        jTextFieldPrecio.setText("");
        jLabelStockAvailable.setText("0");
        jLabelStockOnReturn.setText("0");
        jLabelStockTotal.setText("0");
    }

    public void setSelectedProductData(String code)
    {
        //get product data from DB
        Product prod = productManager.find(code);
        String price = "0.0";
        if (prod != null) {
            jTextFieldArticulo.setText(code);
            jTextAreaDesc.setText(prod.getProductDescriptionLong());
            jTextFieldColor.setText(prod.getProductColor());
            jComboBoxTalle.setSelectedItem(prod.getProductSize());
            jTextFieldNombre.setText(prod.getProductDescription());
            if(prod.getLatestProductPrice() != null){
                price = String.valueOf(prod.getLatestProductPrice().getPriceValue());
            }
            jTextFieldPrecio.setText(price);
            
            ProductStock productStock = stockManager.findByProductId(prod.getProductId());
            int availableStock = 0;
            int returnStock = 0;
            int totalStock = 0;
            
            if(productStock!=null){
                availableStock = productStock.getAvailableAmount();
                returnStock = productStock.getOnReturnAmount();
                totalStock = productStock.getTotalAmount();
            }
            
            jLabelStockAvailable.setText(String.valueOf(availableStock));
            jLabelStockOnReturn.setText(String.valueOf(returnStock));
            jLabelStockTotal.setText(String.valueOf(totalStock));
        }
    }
    
    private void getAllProductsFromDB()
    {
        jTableProducts.setModel(getProductsListModel());
        jTableProducts.setColumnSelectionAllowed(false);
        
    }
    
    private void getAllClientsFromDB()
    {
        jTableClients.setModel(getClientsListModel());
        jTableClients.setColumnSelectionAllowed(false);
        
    }

    private void getAllSuppliersFromDB()
    {
        jTableSuppliers.setModel(getSuppliersListModel());
        jTableSuppliers.setColumnSelectionAllowed(false);
        
    }
    
    private void getAllMatPrimaFromDB()
    {
        jTableMatPrima.setModel(getMatPrimaListModel());
        jTableMatPrima.setColumnSelectionAllowed(false);        
    }
    
    private void getAllOrdersFromDB()
    {
        jTableOrders.setModel(getOrdersListModel());
        jTableOrders.setColumnSelectionAllowed(false);
    }
    
    private void getAllOrdersRawMaterialFromDB()
    {
        jTableOrdersRawMaterial.setModel(getOrdersRawMaterialListModel());
        jTableOrdersRawMaterial.setColumnSelectionAllowed(false);
    }
    
    private void getAllReturnsFromDB()
    {
        jTableReturns.setModel(getReturnsListModel());
        jTableReturns.setColumnSelectionAllowed(false);
        
    }
    
    private void getAllSalesFromDB()
    {
        jTableSales.setModel(uISaleHandler.getSalesListModel());
        jTableSales.setColumnSelectionAllowed(false);
        
    }
    
    private DefaultTableModel getProductsListModel()
    {
        List<Product> products = productManager.list();
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                return false;
            }
        };
        
        String col[] = {"Articulo","Descripcion","Costo","Precio Venta","Stock Disp","Stock Dev", "Stock Total"};
        dm.setColumnIdentifiers(col);
        
        //get data from rows
        for (Product product : products) {
            double price = 0 , cost;
            if(product.getLatestProductPrice()!=null){
                price = product.getLatestProductPrice().getPriceValue();
            }
            
            cost = product.getCost();
        
            //Get the stock data for product
            ProductStock productStock = stockManager.findByProductId(product.getProductId());
            int totalQuantity = 0;
            int availableQuantity = 0;
            int returnQuantity = 0;
            
            if(productStock != null){
                totalQuantity = productStock.getTotalAmount();
                availableQuantity = productStock.getAvailableAmount();
                returnQuantity = productStock.getOnReturnAmount();
            }
            
            dm.addRow(new Object[]{product.getProductCode(), product.getProductDescription(), 
                cost, price, availableQuantity, returnQuantity, totalQuantity});
        
        }
        
        return dm;
    }

    
    private DefaultTableModel getClientsListModel()
    {
        List<Client> clients = clientManager.list();
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                return false;
            }
        };
        
        String col[] = {"Nro Cliente","Nombre","Contacto","email","Tel"};
        dm.setColumnIdentifiers(col);
        
        //get data from rows
        for (Client cli : clients) {
            dm.addRow(new Object[]{cli.getClientId(),cli.getName(),cli.getContactPerson(),cli.getEmail(),cli.getPhoneNumber()});        
        }
        
        return dm;
    }

    private DefaultTableModel getSuppliersListModel()
    {
        List<Supplier> suppliers = supplierManager.list();
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                return false;
            }
        };
        
        String col[] = {"Cod","Nombre","Contacto","email","Tel"};
        dm.setColumnIdentifiers(col);
        
        //get data from rows
        for (Supplier sup : suppliers) {
            dm.addRow(new Object[]{sup.getSupplierId(),sup.getName(),sup.getContactPerson(),sup.getEmail(),sup.getPhone()});        
        }
        
        return dm;
    }
    
    private DefaultTableModel getMatPrimaListModel()
    {
        List<RawMaterial> rawMaterials = rawMaterialManager.list();
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                return false;
            }
        };
        
        String col[] = {"Cod","Nombre","Unidad medida","Cantidad","Precio"};
        dm.setColumnIdentifiers(col);
        
        //get data from rows
        for (RawMaterial rawMaterial : rawMaterials) {
            dm.addRow(new Object[]{rawMaterial.getRawMaterialId(),rawMaterial.getName(),rawMaterial.getMessureUnit(),rawMaterial.getAmount(),rawMaterial.getPrice()});
        
        }
        
        return dm;
    }
    
    private DefaultTableModel getOrdersListModel()
    {
        List<Order> orders = orderManager.list();
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                return false;
            }
        };
        
        String col[] = {"Nro Pedido","Fecha","Proveedor","Monto total"};
        dm.setColumnIdentifiers(col);
        
        SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        
        //get data from rows
        for (Order or : orders) {
            dm.addRow(new Object[]{or.getOrderId(),df.format(or.getOrderDate()),
                or.getSupplier().getName(),or.getTotalOrderAmount()});        
        }
        
        return dm;
    }
    
    private DefaultTableModel getOrdersRawMaterialListModel()
    {
        List<OrderRawMaterial> ordersRawMaterial = orderRawMaterialManager.list();
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                return false;
            }
        };
        
        String col[] = {"Nro Compra","Fecha","Proveedor","Monto total"};
        dm.setColumnIdentifiers(col);
        
        SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        
        //get data from rows
        for (OrderRawMaterial or : ordersRawMaterial) {
            dm.addRow(new Object[]{or.getOrderRawMaterialId(),df.format(or.getOrderRawMaterialDate()),
                or.getSupplier().getName(),or.getTotalOrderRawMaterialAmount()});        
        }
        
        return dm;
    }
    
    private DefaultTableModel getReturnsListModel()
    {
        List<Return> returns = returnManager.list();
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                return false;
            }
        };
        
        String col[] = {"Nro Devolucion","Nro Pedido","Fecha","Proveedor"};
        dm.setColumnIdentifiers(col);
        
        SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        
        //get data from rows
        for (Return ret : returns) {
            dm.addRow(new Object[]{ret.getReturnId(),ret.getOrder().getOrderId(),df.format(ret.getReturnDate()),
                ret.getSupplier().getName()});        
        }
        
        return dm;
    }
            
    private void getSelectedProductData()
    {
        int selectedRowIndex = jTableProducts.getSelectedRow();
        int selectedColumnIndex = 0;
        String codeSelected = (String) jTableProducts.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);
        
        setSelectedProductData(codeSelected);
    }

    private void addTabListenerForProductPanel()
    {
        //
        // Add key listener to change the TAB behaviour in
        // JTextArea to transfer focus to other component forward
        // or backward.
        //
        jTextAreaDesc.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_TAB) {
                    if (e.getModifiers() > 0) {
                        jTextAreaDesc.transferFocusBackward();
                    } else {
                        jTextAreaDesc.transferFocus();
                    }
                    e.consume();
                }
            }
        });
    }

    private void getSelectedClientData()
    {
        int selectedRowIndex = jTableClients.getSelectedRow();
        int selectedColumnIndex = 0;
        int idSelected = (int) jTableClients.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);
        
        setSelectedClientData(idSelected);
    }
    
    public void setSelectedClientData(int id)
    {
        //get client data from DB
        Client cli = clientManager.findById(id);
        if (cli != null) {
            jTextFieldNomCliente.setText(cli.getName());
            jTextFieldEmailCliente.setText(cli.getEmail());
            jTextFieldTelCliente.setText(cli.getPhoneNumber());
            jTextFieldClienteContacto.setText(cli.getContactPerson());
            jTextFieldClienteDir.setText(cli.getAddress());
            jTextFieldClienteWeb.setText(cli.getWebSite());
        }
    }
    
    private void getSelectedOrderData()
    {
        int selectedRowIndex = jTableOrders.getSelectedRow();
        int selectedColumnIndex = 0;
        Long selected = (Long) jTableOrders.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);
        
        setSelectedOrderData(selected);
    }
    
    public void setSelectedOrderData(long id)
    {
        //get data from DB
        Order or = orderManager.find(id);
        
        if (or != null) {
            SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
            this.jTextFieldOrderDate.setText(df.format(or.getOrderDate()));
            Supplier supplier = supplierManager.findById(or.getSupplier().getSupplierId());
            if(supplier!=null){
                jComboBoxProveedor.setSelectedItem(supplier);    
            }
            DefaultTableModel orderProductsList = getOrderDetailProductsModel(or.getDetails());
            jTableProductosPedido.setModel(orderProductsList);
            jTextFieldTotalOrder.setText(String.valueOf(Math.rint(or.getTotalOrderAmount())));
        }
    }
    
    private void getSelectedOrderRawMaterialData()
    {
        int selectedRowIndex = jTableOrdersRawMaterial.getSelectedRow();
        int selectedColumnIndex = 0;
        Long selected = (Long) jTableOrdersRawMaterial.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);
        
        setSelectedOrderRawMaterialData(selected);
    }
    
    public void setSelectedOrderRawMaterialData(long id)
    {
        //get data from DB
        OrderRawMaterial or = orderRawMaterialManager.find(id);
        
        if (or != null) {
            //set the order id for later editing purposes.
            this.jOrderRawMaterialIDTextField.setText(String.valueOf(or.getOrderRawMaterialId()));
            SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
            this.jTextFieldOrderRawMaterialDate.setText(df.format(or.getOrderRawMaterialDate()));
            Supplier supplier = supplierManager.findById(or.getSupplier().getSupplierId());
            if(supplier!=null){
                jComboBoxProveedorRawMaterial.setSelectedItem(supplier);    
            }
            DefaultTableModel orderRawMaterialList = getOrderRawMaterialDetailProductsModel(or.getDetails());
            jTableRawMaterialPedido.setModel(orderRawMaterialList);
            jTextFieldTotalOrderRawMaterial.setText(String.valueOf(Math.rint(or.getTotalOrderRawMaterialAmount())));
        }
    }
    
    private void getSelectedReturnData()
    {
        int selectedRowIndex = jTableReturns.getSelectedRow();
        int selectedColumnIndex = 0;
        Long selected = (Long) jTableReturns.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);
        
        setSelectedReturnData(selected);
    }
    
    public void setSelectedReturnData(long id)
    {
        //get data from DB
        Return ret = returnManager.find(id);
        
        if (ret != null) {
            SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
            this.jTextFieldReturnDate.setText(df.format(ret.getReturnDate()));
            
            DefaultListModel listModel = new DefaultListModel();
            listModel.addElement(ret.getOrder());
            this.jListPedidos.setModel(listModel);
            this.jListPedidos.setSelectedIndex(0);
            
            DefaultTableModel returnProductsList = getReturnDetailProductsModel(ret);
            jTableProductosPedidosDevol.setModel(returnProductsList);
            
        }
    }
    
    private void getSelectedSaleData()
    {
        int selectedRowIndex = jTableSales.getSelectedRow();
        int selectedColumnIndex = 0;
        long selected = (long) jTableSales.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);
        
        setSelectedSaleData(selected);
    }
    
    public void setSelectedSaleData(long id)
    {
        //get data from DB
        Sale sale = uISaleHandler.findSale(id);
        
        if (sale != null) {
            SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
            this.jTextFieldSaleDate.setText(df.format(sale.getSaleDate()));
            
            this.jComboBoxClient.setSelectedItem(sale.getClient());
            
            double totalSale = sale.getTotalSaleAmount();
            double discount = sale.getDiscount();
            double subTot = 0;
            this.jTextFieldDiscountSale.setText(String.valueOf(discount));
            this.jTextFieldTotalSale.setText(String.valueOf(totalSale));
                        
            String discountType = sale.getDiscountType();
            if(Constants.PERCENTAGE_DISCOUNT.equals(discountType)){
                this.jRadioButtonPercentDisc.setSelected(true);
                subTot = totalSale - ((totalSale*discount)/100);
                this.jTextFieldSaleSubTotal.setText(String.valueOf(subTot));
            }else if(Constants.FIXED_DISCOUNT.equals(discountType)){
                this.jRadioButtonFixedDisc.setSelected(true);
                subTot = totalSale - discount;
                this.jTextFieldSaleSubTotal.setText(String.valueOf(subTot));
            }else{
                this.jTextFieldSaleSubTotal.setText(String.valueOf(totalSale));
            }
                       
            if(sale.isCharged()){
                jCheckBoxChargedSale.setSelected(true);
            }else{
                jCheckBoxChargedSale.setSelected(false);
            }
            
            if(sale.isDelivered()){
                jCheckBoxDeliveredSale.setSelected(true);
            }else{
                jCheckBoxDeliveredSale.setSelected(false);
            }
            
            DefaultTableModel saleProductsList = getSaleProductsModel(sale);
            jTableProductosSale.setModel(saleProductsList);
            
        }
    }
    
    public DefaultTableModel getSaleProductsModel(Sale sale)
    {
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                //not allow product or price modifications
                if(col==1)
                {
                    return true;
                }
                return false;
            }
        };
        
        String col[] = {"Producto","Cantidad","Stock Disp.","Precio"};
        dm.setColumnIdentifiers(col);
        //get data from rows
        Set<SaleDetails> saleDetailsList = sale.getDetails();
        for (SaleDetails saleDet : saleDetailsList) {
            Product product = productManager.findById(saleDet.getProduct().getProductId());
            ProductStock stock = stockManager.findByProductId(product.getProductId());
            int amountStock = 0;
            if(stock!=null){
                amountStock = stock.getAvailableAmount();
            }
            String price = String.valueOf(saleDet.getPrice());
            String amount = String.valueOf(saleDet.getAmount());
            dm.addRow(new Object[]{product,amount,amountStock,price});        
        }
    
        dm.addTableModelListener(new TableModelListener()
        {
            public void tableChanged(TableModelEvent e)
            {
                if(e.getColumn() == 1){
                    updateProductSaleAmount(Constants.UPDATE_OPERATION);
                }else if(e.getColumn() == 3){
                    updateProductSaleSubtotal();
                }
                
            }
        });
        
        return dm;
    }
    
    private DefaultTableModel getOrderDetailProductsModel(Set<OrderDetails> orderDetailsList)
    {
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                //not allow product or order amount modifications
                if(col==1 || col==2)
                {
                    return true;
                }
                return false;
            }
        };
        
        String col[] = {"Producto","Cantidad","Costo"};
        dm.setColumnIdentifiers(col);
        
        //get data from rows
        for (OrderDetails or : orderDetailsList) {
            Product product = productManager.findById(or.getProductId());
            String amount = String.valueOf(or.getAmount());
            String cost = String.valueOf(or.getCost());
            dm.addRow(new Object[]{product,amount,cost});        
        }
    
        dm.addTableModelListener(new TableModelListener()
        {
            public void tableChanged(TableModelEvent e)
            {
                if(e.getColumn() == 1){
                    updateProductOrderAmount(Constants.UPDATE_OPERATION);
                }else if(e.getColumn() == 2){
                    updateProductOrderCost();
                }
                
            }
        });
        
        return dm;
    }
    
    private DefaultTableModel getOrderRawMaterialDetailProductsModel(Set<OrderRawMaterialDetails> orderRawMaterialDetailsList)
    {
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                //not allow raw mat or order amount modifications
                if(col==1 || col==2)
                {
                    return true;
                }
                return false;
            }
        };
        
        String col[] = {"Materia Prima","Cant","Costo","Presentacion","Cant Stock"};
        dm.setColumnIdentifiers(col);
        
        //get data from rows
        for (OrderRawMaterialDetails or : orderRawMaterialDetailsList) {
            RawMaterial rawMaterial = rawMaterialManager.findById((int)or.getRawMaterialId());
            RawMaterialStock rawMaterialStock = rawMaterialStockManager.findByRawMaterialId(or.getRawMaterialId());
            String amount = String.valueOf(or.getAmount());
            String cost = String.valueOf(or.getCost());
            String presentation = rawMaterial.getMessureUnit();
            String amountPresentation = "0.0";
            if(rawMaterialStock != null)
            {
                amountPresentation = String.valueOf(rawMaterialStock.getTotalAmount());
            }
            
            dm.addRow(new Object[]{rawMaterial,amount,cost,presentation,amountPresentation});        
        }
    
        dm.addTableModelListener(new TableModelListener()
        {
            public void tableChanged(TableModelEvent e)
            {
                if(e.getColumn() == 1){
                    updateProductOrderRawMaterialAmount(Constants.UPDATE_OPERATION);
                }else if(e.getColumn() == 2){
                    updateProductOrderRawMaterialCost();
                }
                
            }
        });
        
        return dm;
    }
    
    private DefaultTableModel getReturnDetailProductsModel(Return returnOrder)
    {
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                //not allow product or order amount modifications
                if(col==2)
                {
                    return true;
                }
                return false;
            }
        };
        
        String col[] = {"Producto","Cant comprada","Cant a devolver"};
        dm.setColumnIdentifiers(col);
        //get data from rows
        Set<ReturnDetails> returnDetailsList = returnOrder.getDetails();
        for (ReturnDetails retDet : returnDetailsList) {
            Product product = productManager.findById(retDet.getProductId());
            String amount = String.valueOf(retDet.getAmount());
            
            //Get the ordered amount for the product
            Set<OrderDetails> orderDetails = returnOrder.getOrder().getDetails();
            int orderedAmount = 0;
            for (OrderDetails orderDetail : orderDetails) {
                if(orderDetail.getProductId() == product.getProductId()){
                    orderedAmount = orderDetail.getAmount();
                }
            }
            ////////////////////////            
            String amountBought = String.valueOf(orderedAmount);
            dm.addRow(new Object[]{product,amountBought,amount});        
        }
        
        return dm;
    }
        
    
    private void dataClientFormClean()
    {
        this.jTextFieldNomCliente.setText("");
        this.jTextFieldEmailCliente.setText("");
        this.jTextFieldTelCliente.setText("");
        this.jTextFieldClienteContacto.setText("");
        this.jTextFieldClienteDir.setText("");
        this.jTextFieldClienteWeb.setText("");
    }
    
    private void setClientFieldsEditable(boolean b)
    {
        this.jTextFieldNomCliente.setEditable(b);
        this.jTextFieldEmailCliente.setEditable(b);
        this.jTextFieldTelCliente.setEditable(b);
        this.jTextFieldClienteContacto.setEditable(b);
        this.jTextFieldClienteDir.setEditable(b);
        this.jTextFieldClienteWeb.setEditable(b);
    }

    private void dataOrderFormClean()
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        String anioRet = String.valueOf(calendar.get(Calendar.YEAR));
        String mesRet = String.valueOf(calendar.get(Calendar.MONTH)+1);
        String diaRet = String.valueOf(calendar.get(Calendar.DAY_OF_MONTH));
        
                
        this.jTextFieldOrderDate.setText(((diaRet.length()>1)?diaRet:"0"+diaRet)+"/"+((mesRet.length()>1)?mesRet:"0"+mesRet)+"/"+anioRet);
        
        
        if(jComboBoxProveedor.getModel().getSize()>0){
            this.jComboBoxProveedor.setSelectedIndex(0);
        }
        
        this.jTextFieldBuscarProd.setText("");
        this.jTableProductosPedido.setModel(getProductsOrderListModel());
        this.jTextFieldTotalOrder.setText("");
    }
    
    private void dataOrderRawMaterialFormClean()
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        String anioRet = String.valueOf(calendar.get(Calendar.YEAR));
        String mesRet = String.valueOf(calendar.get(Calendar.MONTH)+1);
        String diaRet = String.valueOf(calendar.get(Calendar.DAY_OF_MONTH));
        
                
        this.jTextFieldOrderRawMaterialDate.setText(((diaRet.length()>1)?diaRet:"0"+diaRet)+"/"+((mesRet.length()>1)?mesRet:"0"+mesRet)+"/"+anioRet);
        
        
        if(jComboBoxProveedorRawMaterial.getModel().getSize()>0){
            this.jComboBoxProveedorRawMaterial.setSelectedIndex(0);
        }
        
        this.jTextFieldBuscarRawMaterial.setText("");
        this.jTableRawMaterialPedido.setModel(getRawMaterialOrderListModel());
        this.jTextFieldTotalOrderRawMaterial.setText("");
    }
    
    private void dataSaleFormClean()
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        String anioRet = String.valueOf(calendar.get(Calendar.YEAR));
        String mesRet = String.valueOf(calendar.get(Calendar.MONTH)+1);
        String diaRet = String.valueOf(calendar.get(Calendar.DAY_OF_MONTH));
        
        this.jTextFieldSaleDate.setText(((diaRet.length()>1)?diaRet:"0"+diaRet)+"/"+((mesRet.length()>1)?mesRet:"0"+mesRet)+"/"+anioRet);
        
        if(jComboBoxClient.getModel().getSize()>0){
            this.jComboBoxClient.setSelectedIndex(0);
        }
        
        this.jTextFieldBuscarProdSale.setText("");
        this.jTableProductosSale.setModel(getProductsSaleListModel());
        this.jTextFieldDiscountSale.setText("");
        this.jTextFieldSaleSubTotal.setText("0.0");
        this.jTextFieldTotalSale.setText("0.0");
        this.jCheckBoxChargedSale.setSelected(true);
        this.jCheckBoxDeliveredSale.setSelected(true);
        this.jButtonCalTotalSale.setEnabled(false);
    }
    
    private void setOrderFieldsEditable(boolean b)
    {
        this.jTextFieldOrderDate.setEnabled(b);
        this.jComboBoxProveedor.setEnabled(b);
        this.jTextFieldBuscarProd.setEditable(b);
        this.jListProductos.setEnabled(b);
        this.jTableProductosPedido.setEnabled(b);
        this.jTextFieldTotalOrder.setEnabled(b);
    }
    
    private void setOrderRawMaterialFieldsEditable(boolean b)
    {
        this.jTextFieldOrderRawMaterialDate.setEnabled(b);
        this.jComboBoxProveedorRawMaterial.setEnabled(b);
        this.jTextFieldBuscarRawMaterial.setEditable(b);
        this.jListRawMaterial.setEnabled(b);
        this.jTableRawMaterialPedido.setEnabled(b);
        this.jTextFieldTotalOrderRawMaterial.setEnabled(b);
    }
    
    private void setSaleFieldsEditable(boolean b)
    {
        this.jTextFieldSaleDate.setEditable(b);
        this.jComboBoxClient.setEnabled(b);
        this.jTextFieldBuscarProdSale.setEditable(b);
        this.jListProductosSale.setEnabled(b);
        this.jButtonBuscarProductosSale.setEnabled(b);
        this.jTableProductosSale.setEnabled(b);
        this.jRadioButtonFixedDisc.setEnabled(b);
        this.jRadioButtonPercentDisc.setEnabled(b);
        this.jCheckBoxChargedSale.setEnabled(b);
        this.jCheckBoxDeliveredSale.setEnabled(b);
        this.jButtonCalTotalSale.setEnabled(b);
        this.jTextFieldDiscountSale.setEnabled(b);
    }
    
    private void deleteProduct()
    {
        int res = JOptionPane.showConfirmDialog(null, "Confirma borrado?");
        if (res == 0) 
        {
            try 
            {
                Product product = getProductData();
                productManager.deleteProduct(product);
            } 
            catch (Exception e2) 
            {
                JOptionPane.showMessageDialog(null, e2.getMessage());
            }
        }
    }
    
    private void deleteClient()
    {
        int res = JOptionPane.showConfirmDialog(null, "Confirma borrado?");
        if (res == 0) {
            try {
                Client client = getClientData();
                clientManager.deleteClient(client);
            } catch (Exception e2) {
                JOptionPane.showMessageDialog(null, e2.getMessage());
            }
        }
    }

    private void deleteOrder() throws Exception
    {
        int res = JOptionPane.showConfirmDialog(null, "Confirma borrado?");
        if (res == 0) {
            try {
                int selectedRowIndex = jTableOrders.getSelectedRow();
                int selectedColumnIndex = 0;
                Long selected = (Long) jTableOrders.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);

                Order order = orderManager.find(selected);

                if (order != null) {
                    //check if there are returns for this order
                    List<Return> return1 = returnManager.findByOrder(order);
                    if (return1 != null && !return1.isEmpty()) {
                        throw new Exception("No se puede eliminar la compra. Existen una o mas devoluciones asociadas");
                    }

                    List<Long> productIds = new ArrayList<>();
                    Map<Long, Integer> orderProdDetails = new HashMap();
                    for (OrderDetails details : order.getDetails()) {
                        productIds.add(details.getProductId());
                        orderProdDetails.put(details.getProductId(), details.getAmount());
                    }
                    orderManager.deleteOrder(order);
                    updateProductStockForDeletedOrder(productIds, orderProdDetails);
                }

            } catch (Exception e2) {
                throw e2;
            }
        }
    }
    
    private void deleteOrderRawMaterial() throws Exception
    {
        int res = JOptionPane.showConfirmDialog(null, "Confirma borrado?");
        if (res == 0) {
            try {
                int selectedRowIndex = jTableOrdersRawMaterial.getSelectedRow();
                int selectedColumnIndex = 0;
                Long selected = (Long) jTableOrdersRawMaterial.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);

                OrderRawMaterial order = orderRawMaterialManager.find(selected);

                if (order != null) {
                    orderRawMaterialManager.deleteOrderRawMaterial(order);
                }
            } catch (Exception e2) {
                throw e2;
            }
        }
    }
    
    private void deleteSale() throws Exception
    {
        int res = JOptionPane.showConfirmDialog(null, "Confirma borrado?");
        if (res == 0) {
            try {
                int selectedRowIndex = jTableSales.getSelectedRow();
                int selectedColumnIndex = 0;
                Long selected = (Long) jTableSales.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);

                uISaleHandler.DeleteSale(selected);
            } catch (Exception e2) {
                throw e2;
            }
        }
    }
    
    private void deleteReturn() throws Exception
    {
        int res = JOptionPane.showConfirmDialog(null, "Confirma borrado?");
        if (res == 0) {
            try {
                int selectedRowIndex = jTableReturns.getSelectedRow();
                int selectedColumnIndex = 0;
                Long selected = (Long) jTableReturns.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);

                Return returnOrder = returnManager.find(selected);

                if (returnOrder != null) {
                    List<Long> productIds = new ArrayList<>();
                    Map<Long, Integer> returnOrderProdDetails = new HashMap();
                    for (ReturnDetails details : returnOrder.getDetails()) {
                        productIds.add(details.getProductId());
                        returnOrderProdDetails.put(details.getProductId(), details.getAmount());
                    }
                    returnManager.deleteReturn(returnOrder);
                    updateProductStockForDeletedReturn(productIds, returnOrderProdDetails);
                }
            } catch (Exception e2) {
                throw e2;
            }
        }
    }
    
    private void deleteSupplier()
    {
        int res = JOptionPane.showConfirmDialog(null, "Confirma borrado?");
        if (res == 0) 
        {   
            Supplier supplier = getSupplierData();
            supplierManager.deleteSupplier(supplier);   
        }
        
    }
    
    private void deleteMatPrima()
    {
        int res = JOptionPane.showConfirmDialog(null, "Confirma borrado?. "
                + "Se eliminara la materia prima de todos los productos que la contengan!");
        if (res == 0) {
            try {
                RawMaterial rawMaterial = getRawMaterialData();
                rawMaterialManager.deleteRawMaterial(rawMaterial);
            } catch (Exception e2) {
                JOptionPane.showMessageDialog(null, e2.getMessage());
            }
        }
    }
    
    private void dataSupplierFormClean()
    {
        this.jTextFieldNomSupplier.setText("");
        this.jTextFieldProvContacto.setText("");
        this.jTextFieldProvDir.setText("");
        this.jTextFieldProvEmail.setText("");
        this.jTextFieldProvTel.setText("");
        this.jTextFieldProvWeb.setText("");
    }

    private void dataMatPrimaFormClean()
    {
        this.jTextFieldMatPrimaCant.setText("");
        this.jTextFieldMatPrimaNom.setText("");
        this.jTextFieldMatPrimaPrecio.setText("");
    }
    
    private void setSupplierFieldsEditable(boolean b)
    {
        this.jTextFieldNomSupplier.setEditable(b);
        this.jTextFieldProvContacto.setEditable(b);
        this.jTextFieldProvDir.setEditable(b);
        this.jTextFieldProvEmail.setEditable(b);
        this.jTextFieldProvTel.setEditable(b);
        this.jTextFieldProvWeb.setEditable(b);
    }

    private void getSelectedSupplierData()
    {
        int selectedRowIndex = jTableSuppliers.getSelectedRow();
        int selectedColumnIndex = 0;
        int suppId = (int) jTableSuppliers.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);
        
        setSelectedSupplierData(suppId);
    }

    private void setSelectedSupplierData(int suppId)
    {
        //get data from DB
        Supplier supp = supplierManager.findById(suppId);
        if (supp != null) {
            jTextFieldNomSupplier.setText(supp.getName());
            jTextFieldProvContacto.setText(supp.getContactPerson());
            jTextFieldProvDir.setText(supp.getAddress());
            jTextFieldProvEmail.setText(supp.getEmail());
            jTextFieldProvTel.setText(supp.getPhone());
            jTextFieldProvWeb.setText(supp.getWebSite());
        }
    }
    
    private void getSelectedMatPrimaData()
    {
        int selectedRowIndex = jTableMatPrima.getSelectedRow();
        int selectedColumnIndex = 0;
        int idSelected = (int) jTableMatPrima.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);
        
        setSelectedMatPrimaData(idSelected);
    }

    private int getSelectedMatPrimaId()
    {
        int idSelected = 0;
        int selectedRowIndex = jTableMatPrima.getSelectedRow();
        if (selectedRowIndex >= 0) {
            int selectedColumnIndex = 0;
            idSelected = (int) jTableMatPrima.getModel().getValueAt(selectedRowIndex, selectedColumnIndex);
        }

        return idSelected;
    }
    
    private void setSelectedMatPrimaData(int idSelected)
    {
        //get data from DB
        RawMaterial material = rawMaterialManager.findById(idSelected);
        if (material != null) {
            jTextFieldMatPrimaCant.setText(String.valueOf(material.getAmount()));
            jTextFieldMatPrimaNom.setText(material.getName());
            jTextFieldMatPrimaPrecio.setText(String.valueOf(material.getPrice()));
            jComboBoxUniMedida.setSelectedItem(material.getMessureUnit());
        }
    }

    private void fillSupplierComboBox()
    {
        List<Supplier> suppliers = supplierManager.list();
        for (Supplier supplier : suppliers) 
        {
            boolean add = true;
            for (int i = 0; i < this.jComboBoxProveedor.getModel().getSize(); i++) {
                Supplier sup = (Supplier) this.jComboBoxProveedor.getModel().getElementAt(i);
                if(supplier.equals(sup))
                {
                    add = false;
                }
            }
            if(add)
            {
                this.jComboBoxProveedor.addItem(supplier);    
            }
        }        
    }

    private void fillClientsComboBox()
    {
        List<Client> clients = clientManager.list();
        for (Client client : clients) 
        {
            boolean add = true;
            for (int i = 0; i < this.jComboBoxClient.getModel().getSize(); i++) {
                Client cli = (Client) this.jComboBoxClient.getModel().getElementAt(i);
                if(client.equals(cli))
                {
                    add = false;
                }
            }
            if(add)
            {
                this.jComboBoxClient.addItem(client);    
            }
        }        
    }
    
    private void findProducts()
    {
        String textToFind = jTextFieldBuscarProd.getText();
        List<Product> products = productManager.findByName(textToFind);
        DefaultListModel listModel = new DefaultListModel();
        for (Product product : products) 
        {
            listModel.addElement(product);
        }
        jListProductos.setModel(listModel);
    }

    private void findProductsPrice()
    {
        String textToFind = jTextFieldBuscarProdActualizar.getText();
        List<Product> products = productManager.findByName(textToFind);
        DefaultListModel listModel = new DefaultListModel();
        for (Product product : products) 
        {
            listModel.addElement(product);
        }
        jListProductosActualizar.setModel(listModel);
    }
    
    private void findRawMaterials()
    {
        String textToFind = jTextFieldBuscarRawMaterial.getText();
        List<RawMaterial> rawMaterials = rawMaterialManager.find(textToFind);
        DefaultListModel listModel = new DefaultListModel();
        for (RawMaterial rawMaterial : rawMaterials) 
        {
            listModel.addElement(rawMaterial);
        }
        jListRawMaterial.setModel(listModel);
    }
    
    private void findProductsSale()
    {
        String textToFind = jTextFieldBuscarProdSale.getText();
        List<Product> products = productManager.findByName(textToFind);
        DefaultListModel listModel = new DefaultListModel();
        for (Product product : products) 
        {
            listModel.addElement(product);
        }
        jListProductosSale.setModel(listModel);
    }
    
    private void updateProductStockForNewOrder(Map<Long, Integer> orderProducts, String operation)
    {
        Set<Long> products = orderProducts.keySet();
        for (Long productId : products) {
            Product product = productManager.findById(productId);
            
            ProductStock stock = stockManager.findByProductId(productId);
                            
            if (stock != null) {
                int orderAmountToUpdate = orderProducts.get(productId);
                int availableAmount = stock.getAvailableAmount();
                int totalAmount = stock.getTotalAmount();
                
                if(operation.equals(Constants.ADD_OPERATION))
                {
                    availableAmount+= orderAmountToUpdate;
                    totalAmount+= orderAmountToUpdate;
                }
                else if(operation.equals(Constants.DELETE_OPERATION))
                {
                    availableAmount-= orderAmountToUpdate;
                    totalAmount-= orderAmountToUpdate;
                }
                
                stock.setAvailableAmount(availableAmount);
                stock.setTotalAmount(totalAmount);
            }
            else{
                int orderAmount = orderProducts.get(productId);
                stock = new ProductStock(product, orderAmount, 0, orderAmount);
            }
            
            stockManager.saveProductStock(stock);
            
        }
    }
    
    private void updateProductStockForDeletedOrder(List<Long> productIds, Map<Long,Integer> orderDetails)
    {
        for (Long id : productIds)
        {
            ProductStock stock = stockManager.findByProductId(id);
            if(stock != null)
            {
                int availableAmount;
                int totalAmount;
                availableAmount = stock.getAvailableAmount() - orderDetails.get(id);
                totalAmount = stock.getTotalAmount() - orderDetails.get(id);
                
                ProductStock newStock = new ProductStock(stock.getProduct(), (availableAmount>0)?availableAmount:0,
                        stock.getOnReturnAmount(), (totalAmount>0)?totalAmount:0);
                
                stockManager.saveProductStock(newStock);
            }
        }
    }
     
    private void updateProductStockForDeletedReturn(List<Long> productIds, Map<Long,Integer> returnDetails)
    {
        for (Long id : productIds)
        {
            ProductStock stock = stockManager.findByProductId(id);
            if(stock != null)
            {
                int availableAmount;
                int returnedAmount;
                availableAmount = stock.getAvailableAmount() + returnDetails.get(id);
                returnedAmount = stock.getOnReturnAmount() - returnDetails.get(id);
                        
                ProductStock newStock = new ProductStock(stock.getProduct(), 
                        (availableAmount>0)?availableAmount:0,
                        returnedAmount, stock.getTotalAmount());
                
                stockManager.saveProductStock(newStock);
            }
        }
    }
    
    private void updateProductStockForNewSale(Map<Long, Integer> sellProducts, String operation)
    {
        Set<Long> products = sellProducts.keySet();
        for (Long productId : products) {
            Product product = productManager.findById(productId);
            
            ProductStock stock = stockManager.findByProductId(productId);
                            
            if (stock != null) {
                int saleAmountToUpdate = sellProducts.get(productId);
                int availableAmount = stock.getAvailableAmount();
                int totalAmount = stock.getTotalAmount();
                
                if(operation.equals(Constants.ADD_OPERATION))
                {
                    availableAmount-= saleAmountToUpdate;
                    totalAmount-= saleAmountToUpdate;
                }
                else if(operation.equals(Constants.DELETE_OPERATION))
                {
                    availableAmount+= saleAmountToUpdate;
                    totalAmount+= saleAmountToUpdate;
                }
                
                stock.setAvailableAmount(availableAmount);
                stock.setTotalAmount(totalAmount);
            }
            else{
                int orderAmount = sellProducts.get(productId);
                stock = new ProductStock(product, orderAmount, 0, orderAmount);
            }
            
            stockManager.saveProductStock(stock);
            
        }
    }
    
    private void updateProductStockForReturn(Map<Long,Integer> productsWithAmountReturn, String operation)
    {
        Set<Long> products = productsWithAmountReturn.keySet();
        for (Long productId : products) {
            
            ProductStock stock = stockManager.findByProductId(productId);
                            
            if (stock != null) {
                int returnAmountToUpdate = productsWithAmountReturn.get(productId);
                int availableAmount = stock.getAvailableAmount();
                int returnAmount = stock.getOnReturnAmount();
                
                if(operation.equals(Constants.ADD_OPERATION))
                {
                    availableAmount-= returnAmountToUpdate;
                    returnAmount+= returnAmountToUpdate;
                }
                else if(operation.equals(Constants.DELETE_OPERATION))
                {
                    availableAmount+= returnAmountToUpdate;
                    returnAmount-= returnAmountToUpdate;
                }
                
                stock.setAvailableAmount(availableAmount);
                stock.setOnReturnAmount(returnAmount);
            }
            
            stockManager.saveProductStock(stock);
            
        }
        
    }

    private void dataReturnFormClean() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        String anioRet = String.valueOf(calendar.get(Calendar.YEAR));
        String mesRet = String.valueOf(calendar.get(Calendar.MONTH)+1);
        String diaRet = String.valueOf(calendar.get(Calendar.DAY_OF_MONTH));
        
                
        this.jTextFieldReturnDate.setText(((diaRet.length()>1)?diaRet:"0"+diaRet)
                +"/"+((mesRet.length()>1)?mesRet:"0"+mesRet)+"/"+anioRet);
        
        this.jTextFieldSupplier.setText("");
        this.jTextFieldDateSince.setText("");
        this.jTextFieldDateTo.setText("");
        
        this.jListPedidos.setModel(new DefaultListModel());
        this.jTableProductosPedidosDevol.setModel(getProductsOrderReturnsListModel());
        this.jTableProductosPedidosDevol.getColumnModel().getColumn(0).setPreferredWidth(100);
        this.jTableProductosPedidosDevol.getColumnModel().getColumn(1).setPreferredWidth(7);
        this.jTableProductosPedidosDevol.getColumnModel().getColumn(2).setPreferredWidth(7);
    }

    private TableModel getProductsOrderReturnsListModel() {
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                //not allow product or order amount modifications
                if(col==2)
                {
                    return true;
                }
                return false;
            }
        };
        
        String col[] = {"Producto","Cant comprada","Cant a devolver"};
        dm.setColumnIdentifiers(col);
        
        
        return dm;        
    }

    private void setReturnFieldsEditable(boolean b) {
        this.jTextFieldReturnDate.setEnabled(b);
        this.jTextFieldDateSince.setEnabled(b);
        this.jTextFieldDateTo.setEnabled(b);
        this.jTextFieldSupplier.setEnabled(b);
        this.jListPedidos.setEnabled(b);
        this.jTableProductosPedidosDevol.setEnabled(b);
        this.jButtonBuscarPedidos.setEnabled(b);
        this.jRadioButtonDateSearch.setEnabled(b);
        this.jRadioButtonSupplierSearch.setEnabled(b);
    }

    private void findOrders() throws Exception {
        List<Order> orders = null;
        DefaultListModel listModel = new DefaultListModel();
        
        if(this.jRadioButtonDateSearch.isSelected()) 
        {
            SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
            Date initialDate;
            Date finalDate = new Date();
            try 
            {
                if((jTextFieldDateSince.getText().equals("  /  /    ") || jTextFieldDateSince.getText().isEmpty())
                        && (jTextFieldDateTo.getText().equals("  /  /    ") || jTextFieldDateTo.getText().isEmpty()))
                {
                    //Find all orders
                    orders = orderManager.list();
                }
                else if(!jTextFieldDateSince.getText().equals("  /  /    ") && !jTextFieldDateSince.getText().isEmpty())
                {
                    initialDate = df.parse(jTextFieldDateSince.getText());
                    if(!jTextFieldDateTo.getText().equals("  /  /    ") && !jTextFieldDateTo.getText().isEmpty())
                    {
                        finalDate = df.parse(jTextFieldDateTo.getText());
                    }
                    orders = orderManager.findByDateRange(initialDate, finalDate);                    
                }
                else
                {
                    throw new Exception("La fecha de inicio no es correcta");
                }
            }
            catch (ParseException ex) 
            {
                throw new Exception("Ocurrio un error listando las compras");
            }
        }
        else if(this.jRadioButtonSupplierSearch.isSelected())
        {
            orders = orderManager.findBySupplier(jTextFieldSupplier.getText());            
        }
        
        if(orders != null)
        {
            for (Order order : orders) 
            {
                listModel.addElement(order);
            }
        }
                
        jListPedidos.setModel(listModel);
    }

    private Vector getProductReturnDetails()
    {
        return ((DefaultTableModel)jTableProductosPedidosDevol.getModel()).getDataVector();
    }

    private Vector getProductOrderDetails()
    {
        return ((DefaultTableModel)jTableProductosPedido.getModel()).getDataVector();
    }
    
    private Vector getProductSaleDetails()
    {
        return ((DefaultTableModel)jTableProductosSale.getModel()).getDataVector();
    }
    
    private void setDataSelectedInReturnPanel()
    {
        jReturnsPanel.setVisible(true);
        getSelectedReturnData();
        setReturnFieldsEditable(false);
        jButtonEditReturn.setEnabled(true);
        jButtonEliminarReturn.setEnabled(true);
        jButtonGuardarReturn.setEnabled(false);
        jRadioButtonDateSearch.setEnabled(false);
        setOrderSearchFieldsVisible(false);
    }

    private void setDataSelectedInSalesPanel()
    {
        jSalesPanel.setVisible(true);
        getSelectedSaleData();
        setSaleFieldsEditable(false);
        jButtonEditSale.setEnabled(true);
        jButtonEliminarSale.setEnabled(true);
        jButtonGuardarSale.setEnabled(false);
    }
    
    private void setOrderSearchFieldsVisible(boolean b)
    {
        this.jLabelDateSince.setVisible(false);
        this.jLabelDateTo.setVisible(false);
        this.jLabelSupplier.setVisible(false);
        this.jTextFieldDateSince.setVisible(false);
        this.jTextFieldDateTo.setVisible(false);
        this.jTextFieldSupplier.setVisible(false);
    }

    private Map<Long, Integer> getAlreadyReturnedAmountForOrderProducts(Return originalReturnOrder)
    {
        Map<Long, Integer> result = new HashMap<>();
        if (originalReturnOrder != null) {
            Set<ReturnDetails> productReturnDetails = originalReturnOrder.getDetails();
            for (ReturnDetails returnDetail : productReturnDetails) {
                result.put(returnDetail.getProductId(), returnDetail.getAmount());
            }
        }
        
        return result;        
    }

    
    
    private Map<Long, Integer> getAlreadyOrderedAmountForOrderProducts(Order originalOrder)
    {
        Map<Long, Integer> result = new HashMap<>();
        if (originalOrder != null) {
            Set<OrderDetails> productOrderDetails = originalOrder.getDetails();
            for (OrderDetails orderDetail : productOrderDetails) {
                result.put(orderDetail.getProductId(), orderDetail.getAmount());
            }
        }
        
        return result;        
    }
    
    private double getTotalForSale()
    {
        double subTotal = Double.valueOf(jTextFieldSaleSubTotal.getText());
        double discount = (jTextFieldDiscountSale.getText().isEmpty())?0:Double.valueOf(jTextFieldDiscountSale.getText());
        double total = 0;
        if(jRadioButtonFixedDisc.isSelected())
        {
            total = subTotal - discount;
        }
        else if(jRadioButtonPercentDisc.isSelected())
        {
            total = subTotal - ((subTotal * discount)/100);        
        }
        else
        {
            total = subTotal;
        }
        
        return total;
    }

    private void updateProductOrderAmount(String operation)
    {
        int selected = jTableProductosPedido.getSelectedRow();
        if (selected >= 0) {
            DefaultTableModel productsOrder = (DefaultTableModel) jTableProductosPedido.getModel();

            Vector object = (Vector) productsOrder.getDataVector().get(selected);
            Product product = (Product) object.get(0);
            String amount = (String) object.get(1);
            double cost = product.getCost();
            
            //object.set(1, String.valueOf(amount));
            double totalPrice = Double.valueOf((String) object.get(2));
            totalPrice = cost * Double.valueOf(amount);
            object.set(2, String.valueOf(totalPrice));
            
            if(Double.valueOf(amount) == 0){
                if (operation.equals(Constants.ADD_OPERATION)) {
                    productsOrder.removeRow(selected);
                }
            }
            

            productsOrder.fireTableDataChanged();
            jTableProductosPedido.setModel(productsOrder);
            jTextFieldTotalOrder.setText(String.valueOf(Math.rint(calculateTotalOrderCost())));
        }
    }

    private void updateProductOrderRawMaterialAmount(String operation)
    {
        int selected = jTableRawMaterialPedido.getSelectedRow();
        if (selected >= 0) {
            DefaultTableModel rawMaterialsOrder = (DefaultTableModel) jTableRawMaterialPedido.getModel();

            Vector object = (Vector) rawMaterialsOrder.getDataVector().get(selected);
            RawMaterial rawMaterial = (RawMaterial) object.get(0);
            String amount = (String) object.get(1);
            double cost = rawMaterial.getPrice();
            
            double totalPrice = Double.valueOf((String) object.get(2));
            totalPrice = cost * Double.valueOf(amount);
            object.set(2, String.valueOf(totalPrice));
            
            
            
            //Presentacion
            String presentation = rawMaterial.getMessureUnit();
            object.set(3, presentation);
            //Stock en base a presentacion y cantidad
            double amountRawMaterial = rawMaterial.getAmount();
            double stockPresentation = amountRawMaterial * Double.valueOf(amount);
            object.set(4, String.valueOf(stockPresentation));
            
            if(Double.valueOf(amount) == 0){
                if (operation.equals(Constants.ADD_OPERATION)) {
                    rawMaterialsOrder.removeRow(selected);
                }
            }
                    
            rawMaterialsOrder.fireTableDataChanged();
            jTableRawMaterialPedido.setModel(rawMaterialsOrder);
            jTextFieldTotalOrderRawMaterial.setText(String.valueOf(Math.rint(calculateTotalOrderRawMaterialCost())));
        }
    }
    
    private void updateProductSaleAmount(String operation)
    {
        int selected = jTableProductosSale.getSelectedRow();
        if (selected >= 0) {
            DefaultTableModel productsOrder = (DefaultTableModel) jTableProductosSale.getModel();

            Vector object = (Vector) productsOrder.getDataVector().get(selected);
            Product product = (Product) object.get(0);
            String amount = (String) object.get(1);
            double price = product.getLatestProductPrice().getPriceValue();
            
            double totalPrice = Double.valueOf((String) object.get(3));
            totalPrice = price * Double.valueOf(amount);
            object.set(3, String.valueOf(totalPrice));
            
            if(Double.valueOf(amount) == 0){
                if (operation.equals(Constants.ADD_OPERATION)) {
                    productsOrder.removeRow(selected);
                }
            }
            
            productsOrder.fireTableDataChanged();
            jTableProductosSale.setModel(productsOrder);
            jTextFieldSaleSubTotal.setText(String.valueOf(calculateSubTotalSale()));
        }
    }
    
    private void updateProductOrderCost()
    {
        int selected = jTableProductosPedido.getSelectedRow();
        if (selected >= 0) {
            jTextFieldTotalOrder.setText(String.valueOf(Math.rint(calculateTotalOrderCost())));
        }
    }
    
    private void updateProductOrderRawMaterialCost()
    {
        int selected = jTableRawMaterialPedido.getSelectedRow();
        if (selected >= 0) {
            jTextFieldTotalOrderRawMaterial.setText(String.valueOf(Math.rint(calculateTotalOrderRawMaterialCost())));
        }
    }
    
    private void updateProductSaleSubtotal()
    {
        int selected = jTableProductosSale.getSelectedRow();
        if (selected >= 0) {
            jTextFieldSaleSubTotal.setText(String.valueOf(Math.rint(calculateSubTotalSale())));
        }
    }
    
    private double calculateTotalOrderCost()
    {
        double totalOrder = 0;
        DefaultTableModel productsOrderTable = (DefaultTableModel) jTableProductosPedido.getModel();

         for (Iterator it = productsOrderTable.getDataVector().iterator(); it.hasNext();) {
            Vector object = (Vector)it.next();
            String cost = (String)object.get(2);
            totalOrder+= Double.valueOf(cost);
        }
            
         return Math.rint(totalOrder);
    }

    private double calculateTotalOrderRawMaterialCost()
    {
        double totalOrder = 0;
        DefaultTableModel rawMaterialsOrderTable = (DefaultTableModel) jTableRawMaterialPedido.getModel();

         for (Iterator it = rawMaterialsOrderTable.getDataVector().iterator(); it.hasNext();) {
            Vector object = (Vector)it.next();
            String cost = (String)object.get(2);
            totalOrder+= Double.valueOf(cost);
        }
            
         return Math.rint(totalOrder);
    }
    
    private double calculateSubTotalSale()
    {
        double totalSale = 0;
        DefaultTableModel productsOrderTable = (DefaultTableModel) jTableProductosSale.getModel();

         for (Iterator it = productsOrderTable.getDataVector().iterator(); it.hasNext();) {
            Vector object = (Vector)it.next();
            String price = (String)object.get(3);
            totalSale+= Double.valueOf(price);
        }
            
         return Math.rint(totalSale);
    }
    
    private void setProductData()
    {
        jProductsPanel.setVisible(true);
        getSelectedProductData();
        setProductFieldsEditable(false);
        jButtonEditProduct.setEnabled(true);
        jButtonEliminarProducto.setEnabled(true);
        jButtonGuardarProducto.setEnabled(false);        
    }

    private void selectOrderRawMaterial()
    {
        jOrdersRawMaterialPanel.setVisible(true);
        jOrderRawMaterialIDTextField.setVisible(false);
        getSelectedOrderRawMaterialData();
        setOrderRawMaterialFieldsEditable(false);
        jButtonEditOrderRawMaterial.setEnabled(true);
        jButtonEliminarOrderRawMaterial.setEnabled(true);
        jButtonGuardarOrderRawMaterial.setEnabled(false);
    }

    private void fillSupplierComboBoxRawMaterial()
    {
        List<Supplier> suppliers = supplierManager.list();
        for (Supplier supplier : suppliers) 
        {
            boolean add = true;
            for (int i = 0; i < this.jComboBoxProveedorRawMaterial.getModel().getSize(); i++) {
                Supplier sup = (Supplier) this.jComboBoxProveedorRawMaterial.getModel().getElementAt(i);
                if(supplier.equals(sup))
                {
                    add = false;
                }
            }
            if(add)
            {
                this.jComboBoxProveedorRawMaterial.addItem(supplier);    
            }
        }
    }

    private void selectMateriaPrima()
    {
        jMatPrimaPanel.setVisible(true);
        getSelectedMatPrimaData();
        setMatPrimaFieldsEditable(false);
        jButtonEditarMatPrima.setEnabled(true);
        jButtonEliminarMatPrima.setEnabled(true);
        jButtonGuardarMatPrima.setEnabled(false);
    }

    private void updateProductPrices(String operation) {
        if(!jPorcentajePrecioTextField.getText().isEmpty() 
                && jListProductosActualizar.getModel().getSize() > 0)
        {
            jFixedNewPriceTextField.setText("");
            int percent = Integer.valueOf(jPorcentajePrecioTextField.getText());
            setProductsPriceTable(percent, operation);
            
        }
    }

    private void setProductsPriceTable(double value, String operation) {
        ListModel productsToUpdate = jListProductosActualizar.getModel();
        
        
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                return false;
            }
        };
        
        String col[] = {"Articulo","Descripcion","Precio Venta","Precio Actualizado"};
        dm.setColumnIdentifiers(col);
        
        for (int i = 0; i < productsToUpdate.getSize(); i++) 
        {
            Product product = (Product) productsToUpdate.getElementAt(i);
            double updatedPrice = 0;
            double price = 0;
            if (operation.equals("FIXED")) {
                updatedPrice = value;
            } else {
                price = product.getCost();
                if (price > 0) {
                    double per = ((price * value) / 100);
                    if (operation.equals("+")) {
                        updatedPrice = price + per;
                    } else if (operation.equals("-")) {
                        updatedPrice = price - per;
                    }
                }
            }
                
            updatedPrice = Redondeo.Redondear(updatedPrice,2);
                
            
            
            dm.addRow(new Object[]{product.getProductCode(), product.getProductDescription(), 
                price, updatedPrice});
        
        }
        
        jTableProductosNuevoPrecio.setModel(dm);
    }

    private void dataPricePanelFormClean() {
        
        this.jProductsPanel.setVisible(false);
        this.jSuppliersPanel.setVisible(false);
        this.jClientesPanel.setVisible(false);
        this.jMatPrimaPanel.setVisible(false);
        this.jOrdersPanel.setVisible(false);
        this.jReturnsPanel.setVisible(false);
        this.jSalesPanel.setVisible(false);
        this.jOrdersRawMaterialPanel.setVisible(false);
        
        this.jTextFieldBuscarProdActualizar.setText("");
        this.jPorcentajePrecioTextField.setText("");
        this.jFixedNewPriceTextField.setText("");
        this.jListProductosActualizar.setModel(new DefaultListModel());
        this.jTableProductosNuevoPrecio.setModel(getProductsPriceListModel());     
    }

    private TableModel getProductsPriceListModel()       
    {
        DefaultTableModel dm = new DefaultTableModel()
        {
            @Override
            public boolean isCellEditable(int row, int col)
            {
                if(col==1 || col==2){
                    return true;
                }
                return false;
            }
        };
        
        String col[] = {"Articulo","Descripcion","Precio Venta","Precio Actualizado"};
        dm.setColumnIdentifiers(col);
        return dm;  
    }

    private void updateRawMaterialStock(OrderRawMaterial newOrder, OrderRawMaterial original) {
        
        Map<Integer,Double> rawMaterialOriginalStock = new HashMap<>();
        if(original != null)
        {
            //Update the stock
            Set<OrderRawMaterialDetails> orderDetails = original.getDetails();
            for (OrderRawMaterialDetails orderRawMaterialDetails : orderDetails) 
            {
                RawMaterial material = rawMaterialManager.findById((int) orderRawMaterialDetails.getRawMaterialId());
                if(material != null)
                {
                    double amount = orderRawMaterialDetails.getAmount() * material.getAmount();
                    rawMaterialOriginalStock.put(material.getRawMaterialId(), amount);
                    
                }
            }
        }
        
        Set<OrderRawMaterialDetails> orderDetails = newOrder.getDetails();
        
        for (OrderRawMaterialDetails orderRawMaterialDetails : orderDetails) {
            
            RawMaterial material = rawMaterialManager.findById((int) orderRawMaterialDetails.getRawMaterialId());
            if(material != null)
            {
                double amount = orderRawMaterialDetails.getAmount();
                double amountPresentation = material.getAmount() * amount;
                
                RawMaterialStock rawMaterialStock = rawMaterialStockManager.findByRawMaterialId(material.getRawMaterialId());
                if(rawMaterialStock != null)
                {
                    double currentAmount = rawMaterialStock.getTotalAmount();
                    double newAmount = 0;
                    if(rawMaterialOriginalStock.containsKey(material.getRawMaterialId()))
                    {
                        currentAmount = currentAmount - rawMaterialOriginalStock.get(material.getRawMaterialId());
                    }
                    newAmount = currentAmount + amountPresentation;
                    rawMaterialStock = new RawMaterialStock(material, Redondeo.Redondear(newAmount,2));
                }
                else
                {
                    rawMaterialStock = new RawMaterialStock(material, Redondeo.Redondear(amountPresentation,2));
                }
            
                rawMaterialStockManager.saveRawMaterialStock(rawMaterialStock);
            }
            
        }
    }

    

    
}
